diff --git a/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php b/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php index 91c28994..a5bcfb63 100644 --- a/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php +++ b/app/modules/web/Controllers/AccountFavorite/AccountFavoriteBase.php @@ -24,9 +24,10 @@ namespace SP\Modules\Web\Controllers\AccountFavorite; - use SP\Core\Application; use SP\Domain\Account\Ports\AccountToFavoriteService; +use SP\Domain\Core\Exceptions\SessionTimeout; +use SP\Domain\Core\Exceptions\SPException; use SP\Modules\Web\Controllers\SimpleControllerBase; use SP\Mvc\Controller\SimpleControllerHelper; @@ -35,17 +36,18 @@ use SP\Mvc\Controller\SimpleControllerHelper; */ abstract class AccountFavoriteBase extends SimpleControllerBase { - protected AccountToFavoriteService $accountToFavoriteService; + /** + * @throws SessionTimeout + * @throws SPException + */ public function __construct( - Application $application, - SimpleControllerHelper $simpleControllerHelper, - AccountToFavoriteService $accountToFavoriteService + Application $application, + SimpleControllerHelper $simpleControllerHelper, + protected AccountToFavoriteService $accountToFavoriteService ) { parent::__construct($application, $simpleControllerHelper); $this->checks(); - - $this->accountToFavoriteService = $accountToFavoriteService; } } diff --git a/app/modules/web/Controllers/AccountFavorite/MarkController.php b/app/modules/web/Controllers/AccountFavorite/MarkController.php index 9dad3ced..d791a9bc 100644 --- a/app/modules/web/Controllers/AccountFavorite/MarkController.php +++ b/app/modules/web/Controllers/AccountFavorite/MarkController.php @@ -25,11 +25,14 @@ namespace SP\Modules\Web\Controllers\AccountFavorite; use Exception; -use JsonException; use SP\Core\Events\Event; +use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Http\Dtos\JsonMessage; use SP\Modules\Web\Controllers\Traits\JsonTrait; +use function SP\__u; +use function SP\processException; + /** * Class MarkController * @@ -40,10 +43,10 @@ final class MarkController extends AccountFavoriteBase use JsonTrait; /** - * @param int $accountId + * @param int $accountId * * @return bool - * @throws JsonException + * @throws SPException */ public function markAction(int $accountId): bool { diff --git a/app/modules/web/Controllers/AccountFavorite/UnmarkController.php b/app/modules/web/Controllers/AccountFavorite/UnmarkController.php index 1febc82a..4b191346 100644 --- a/app/modules/web/Controllers/AccountFavorite/UnmarkController.php +++ b/app/modules/web/Controllers/AccountFavorite/UnmarkController.php @@ -25,11 +25,14 @@ namespace SP\Modules\Web\Controllers\AccountFavorite; use Exception; -use JsonException; use SP\Core\Events\Event; +use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Http\Dtos\JsonMessage; use SP\Modules\Web\Controllers\Traits\JsonTrait; +use function SP\__u; +use function SP\processException; + /** * Class MarkController * @@ -40,10 +43,10 @@ final class UnmarkController extends AccountFavoriteBase use JsonTrait; /** - * @param int $accountId + * @param int $accountId * * @return bool - * @throws JsonException + * @throws SPException */ public function unmarkAction(int $accountId): bool { diff --git a/app/modules/web/Controllers/SimpleControllerBase.php b/app/modules/web/Controllers/SimpleControllerBase.php index e2d588fd..099eefc5 100644 --- a/app/modules/web/Controllers/SimpleControllerBase.php +++ b/app/modules/web/Controllers/SimpleControllerBase.php @@ -24,20 +24,20 @@ namespace SP\Modules\Web\Controllers; -use SP\Core\Acl\Acl; use SP\Core\Application; use SP\Core\Events\EventDispatcher; -use SP\Core\PhpExtensionChecker; use SP\Domain\Config\Ports\ConfigDataInterface; -use SP\Domain\Config\Services\ConfigFile; +use SP\Domain\Config\Ports\ConfigFileService; +use SP\Domain\Core\Acl\AclInterface; use SP\Domain\Core\Acl\UnauthorizedPageException; use SP\Domain\Core\Bootstrap\RouteContextData; use SP\Domain\Core\Bootstrap\UriContextInterface; -use SP\Domain\Core\Context\Context; +use SP\Domain\Core\Context\SessionContext; use SP\Domain\Core\Exceptions\SessionTimeout; use SP\Domain\Core\Exceptions\SPException; +use SP\Domain\Core\PhpExtensionCheckerService; use SP\Domain\Core\UI\ThemeInterface; -use SP\Domain\Http\Services\Request; +use SP\Domain\Http\Ports\RequestService; use SP\Modules\Web\Controllers\Traits\WebControllerTrait; use SP\Mvc\Controller\SimpleControllerHelper; @@ -48,17 +48,17 @@ abstract class SimpleControllerBase { use WebControllerTrait; - protected readonly EventDispatcher $eventDispatcher; - protected readonly ConfigFile $config; - protected readonly Context $session; - protected readonly ThemeInterface $theme; - protected readonly Acl $acl; - protected readonly Request $request; - protected readonly PhpExtensionChecker $extensionChecker; - protected readonly ConfigDataInterface $configData; - protected readonly UriContextInterface $uriContext; - protected readonly RouteContextData $routeContextData; - protected string $controllerName; + protected readonly EventDispatcher $eventDispatcher; + protected readonly ConfigFileService $config; + protected readonly SessionContext $session; + protected readonly ThemeInterface $theme; + protected readonly AclInterface $acl; + protected readonly RequestService $request; + protected readonly PhpExtensionCheckerService $extensionChecker; + protected readonly ConfigDataInterface $configData; + protected readonly UriContextInterface $uriContext; + protected readonly RouteContextData $routeContextData; + protected string $controllerName; /** * @throws SessionTimeout diff --git a/tests/SP/Modules/Web/Controllers/AccountFavorite/AccountFavoriteTest.php b/tests/SP/Modules/Web/Controllers/AccountFavorite/AccountFavoriteTest.php new file mode 100644 index 00000000..bb11b8ad --- /dev/null +++ b/tests/SP/Modules/Web/Controllers/AccountFavorite/AccountFavoriteTest.php @@ -0,0 +1,84 @@ +. + */ + +declare(strict_types=1); + +namespace SP\Tests\Modules\Web\Controllers\AccountFavorite; + +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\MockObject\Exception; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; +use SP\Domain\Core\Exceptions\InvalidClassException; +use SP\Infrastructure\File\FileException; +use SP\Tests\IntegrationTestCase; + +/** + * Class AccountFavoriteTest + */ +#[Group('integration')] +class AccountFavoriteTest extends IntegrationTestCase +{ + /** + * @throws NotFoundExceptionInterface + * @throws Exception + * @throws FileException + * @throws InvalidClassException + * @throws ContainerExceptionInterface + */ + public function testMarkAction() + { + $definitions = $this->getModuleDefinitions(); + + $container = $this->buildContainer( + $definitions, + $this->buildRequest('post', 'index.php', ['r' => 'accountFavorite/mark/100']) + ); + + $this->runApp($container); + + $this->expectOutputString('{"status":0,"description":"Favorite added","data":[],"messages":[]}'); + } + + /** + * @throws NotFoundExceptionInterface + * @throws Exception + * @throws FileException + * @throws InvalidClassException + * @throws ContainerExceptionInterface + */ + public function testUnmarkAction() + { + $definitions = $this->getModuleDefinitions(); + + $container = $this->buildContainer( + $definitions, + $this->buildRequest('post', 'index.php', ['r' => 'accountFavorite/unmark/100']) + ); + + $this->runApp($container); + + $this->expectOutputString('{"status":0,"description":"Favorite deleted","data":[],"messages":[]}'); + } +}