cs fixes
Some checks failed
CI / testsuite (pgsql, 8.2, ) (push) Successful in 4m40s
CI / testsuite (pgsql, 8.4, ) (push) Successful in 6m38s
CI / testsuite (mysql, 8.2, ) (push) Successful in 13m43s
CI / testsuite (sqlite, 8.2, ) (push) Successful in 3m45s
CI / testsuite (mysql, 8.4, ) (push) Successful in 19m5s
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Failing after 8m37s
CI / testsuite (sqlite, 8.4, ) (push) Successful in 8m35s
CI / Coding Standard & Static Analysis (push) Successful in 12m3s

This commit is contained in:
2026-02-11 19:27:09 -08:00
parent 013bb2e0a9
commit 534c3ab7dc
2 changed files with 65 additions and 71 deletions

View File

@@ -73,6 +73,7 @@ class ShoppingCartComponent extends Component {
} else { } else {
$cartsQ->where(['session_id' => $sessionId]); $cartsQ->where(['session_id' => $sessionId]);
} }
return $cartsQ->firstOrFail(); return $cartsQ->firstOrFail();
} }

View File

@@ -6,9 +6,6 @@ namespace CakeCarts\Test\TestCase\Controller\Component;
use Cake\Controller\ComponentRegistry; use Cake\Controller\ComponentRegistry;
use Cake\Controller\Controller; use Cake\Controller\Controller;
use Cake\Datasource\Exception\RecordNotFoundException; use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Event\Event;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Response;
use Cake\Http\ServerRequest; use Cake\Http\ServerRequest;
use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase; use Cake\TestSuite\TestCase;
@@ -19,20 +16,21 @@ use CakeCarts\Controller\Component\ShoppingCartComponent;
*/ */
class ShoppingCartComponentTest extends TestCase { class ShoppingCartComponentTest extends TestCase {
use IntegrationTestTrait; use IntegrationTestTrait;
protected ShoppingCartComponent $component; protected ShoppingCartComponent $component;
protected Controller $controller;
/** protected Controller $controller;
/**
* Fixtures * Fixtures
* *
* @var array<string> * @var array<string>
*/ */
protected array $fixtures = [ protected array $fixtures = [
'plugin.CakeCarts.CartItems', 'plugin.CakeCarts.CartItems',
'plugin.CakeCarts.Carts', 'plugin.CakeCarts.Carts',
]; ];
/** /**
* setUp method * setUp method
@@ -41,11 +39,11 @@ class ShoppingCartComponentTest extends TestCase {
*/ */
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$request = new ServerRequest(); $request = new ServerRequest();
$this->controller = new Controller($request); $this->controller = new Controller($request);
$registry = new ComponentRegistry($this->controller); $registry = new ComponentRegistry($this->controller);
$this->component = new ShoppingCartComponent($registry); $this->component = new ShoppingCartComponent($registry);
} }
/** /**
@@ -54,71 +52,66 @@ class ShoppingCartComponentTest extends TestCase {
* @return void * @return void
*/ */
protected function tearDown(): void { protected function tearDown(): void {
unset($this->ShoppingCart); unset($this->component);
parent::tearDown(); parent::tearDown();
} }
/** /**
* @return void * @return void
*/ */
public function testGetCartForUserById() public function testGetCartForUserById() {
{ $this->session([
$this->session([ 'CakeCarts.session_id' => 'cli',
'CakeCarts.session_id' => 'cli', ]);
]); $cart = $this->component->getCartForUserById('74d1aa54-92a2-4039-bc10-61e1190c51ea');
$cart = $this->component->getCartForUserById('74d1aa54-92a2-4039-bc10-61e1190c51ea'); $this->assertNotNull($cart);
$this->assertNotNull($cart); }
}
/** /**
* @return void * @return void
*/ */
public function testGetCartForUserByIdDoesNotExist() public function testGetCartForUserByIdDoesNotExist() {
{ $this->expectException(RecordNotFoundException::class);
$this->expectException(RecordNotFoundException::class); $cart = $this->component->getCartForUserById('74d1aa54-92a2-4039-bc10-61e1190c51ec');
$cart = $this->component->getCartForUserById('74d1aa54-92a2-4039-bc10-61e1190c51ec'); }
}
/** /**
* @return void * @return void
*/ */
public function testGetUserIdField() public function testGetUserIdField() {
{ $this->assertNotNull($this->component->getUserIdField());
$this->assertNotNull($this->component->getUserIdField()); }
}
/** /**
* @return void * @return void
*/ */
public function testGetSessionId() public function testGetSessionId() {
{ $this->assertNotNull($this->component->getSessionId());
$this->assertNotNull($this->component->getSessionId()); }
}
/** /**
* @return void * @return void
*/ */
public function testCheckIfIsOwnCartIsOwnCart() public function testCheckIfIsOwnCartIsOwnCart() {
{ $this->session([
$this->session([ 'CakeCarts.session_id' => 'session_1',
'CakeCarts.session_id' => 'session_1', ]);
]); $cart = $this->fetchTable('Carts')->get('74d1aa54-92a2-4039-bc10-61e1190c51ea');
$cart = $this->fetchTable('Carts')->get('74d1aa54-92a2-4039-bc10-61e1190c51ea'); $this->component->checkIfIsOwnCart($cart);
$this->component->checkIfIsOwnCart($cart); // if exception not thrown test passes
// if exception not thrown test passes $this->assertEquals(1, 1);
$this->assertEquals(1, 1); }
}
/** /**
* @return void * @return void
*/ */
public function testCheckIfIsOwnCartIsNotOwnCart() public function testCheckIfIsOwnCartIsNotOwnCart() {
{ $this->expectExceptionCode(404);
$this->expectExceptionCode(404); $cart = $this->fetchTable('Carts')->get('74d1aa54-92a2-4039-bc10-61e1190c51ec');
$cart = $this->fetchTable('Carts')->get('74d1aa54-92a2-4039-bc10-61e1190c51ec'); $this->component->checkIfIsOwnCart($cart);
$this->component->checkIfIsOwnCart($cart); // if exception not thrown test fails
// if exception not thrown test fails $this->expectException(RecordNotFoundException::class);
$this->expectException(RecordNotFoundException::class); }
}
} }