66 lines
2.6 KiB
PHP
66 lines
2.6 KiB
PHP
<?php
|
|
namespace Tests\Unit\admin\Controllers;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use admin\Controllers\ShopCouponController;
|
|
use Domain\Coupon\CouponRepository;
|
|
|
|
class ShopCouponControllerTest extends TestCase
|
|
{
|
|
private $repository;
|
|
private $controller;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->repository = $this->createMock(CouponRepository::class);
|
|
$this->controller = new ShopCouponController($this->repository);
|
|
}
|
|
|
|
public function testConstructorAcceptsRepository(): void
|
|
{
|
|
$controller = new ShopCouponController($this->repository);
|
|
$this->assertInstanceOf(ShopCouponController::class, $controller);
|
|
}
|
|
|
|
public function testHasMainActionMethods(): void
|
|
{
|
|
$this->assertTrue(method_exists($this->controller, 'list'));
|
|
$this->assertTrue(method_exists($this->controller, 'edit'));
|
|
$this->assertTrue(method_exists($this->controller, 'save'));
|
|
$this->assertTrue(method_exists($this->controller, 'delete'));
|
|
}
|
|
|
|
public function testHasLegacyAliasMethods(): void
|
|
{
|
|
$this->assertTrue(method_exists($this->controller, 'view_list'));
|
|
$this->assertTrue(method_exists($this->controller, 'coupon_edit'));
|
|
$this->assertTrue(method_exists($this->controller, 'coupon_save'));
|
|
$this->assertTrue(method_exists($this->controller, 'coupon_delete'));
|
|
}
|
|
|
|
public function testActionMethodReturnTypes(): void
|
|
{
|
|
$reflection = new \ReflectionClass($this->controller);
|
|
|
|
$this->assertEquals('string', (string)$reflection->getMethod('list')->getReturnType());
|
|
$this->assertEquals('string', (string)$reflection->getMethod('view_list')->getReturnType());
|
|
$this->assertEquals('string', (string)$reflection->getMethod('edit')->getReturnType());
|
|
$this->assertEquals('string', (string)$reflection->getMethod('coupon_edit')->getReturnType());
|
|
$this->assertEquals('void', (string)$reflection->getMethod('save')->getReturnType());
|
|
$this->assertEquals('void', (string)$reflection->getMethod('coupon_save')->getReturnType());
|
|
$this->assertEquals('void', (string)$reflection->getMethod('delete')->getReturnType());
|
|
$this->assertEquals('void', (string)$reflection->getMethod('coupon_delete')->getReturnType());
|
|
}
|
|
|
|
public function testConstructorRequiresCouponRepository(): void
|
|
{
|
|
$reflection = new \ReflectionClass(ShopCouponController::class);
|
|
$constructor = $reflection->getConstructor();
|
|
$params = $constructor->getParameters();
|
|
|
|
$this->assertCount(1, $params);
|
|
$this->assertEquals('Domain\Coupon\CouponRepository', $params[0]->getType()->getName());
|
|
}
|
|
}
|
|
|