diff --git a/tests/Mock/BaseMock.php b/tests/Mock/BaseMock.php index 3cc29621..297e63cf 100644 --- a/tests/Mock/BaseMock.php +++ b/tests/Mock/BaseMock.php @@ -6,6 +6,7 @@ use MyParcelNL\Pdk\Base\Contract\Arrayable; use MyParcelNL\Pdk\Base\Support\Arr; +use MyParcelNL\Pdk\Base\Support\Utils; use MyParcelNL\Sdk\src\Support\Str; class BaseMock implements Arrayable @@ -120,7 +121,13 @@ public function setAttribute(string $key, $value): self */ public function toArray(?int $flags = null): array { - return $this->attributes; + $attributes = $flags & Arrayable::SKIP_NULL ? Utils::filterNull($this->attributes) : $this->attributes; + + return array_map(static function ($value) use ($flags) { + return $value instanceof Arrayable + ? $value->toArray($flags) + : $value; + }, $attributes); } /** diff --git a/tests/Mock/MockPsObjectModel.php b/tests/Mock/MockPsObjectModel.php index 41980bf9..bc672f53 100644 --- a/tests/Mock/MockPsObjectModel.php +++ b/tests/Mock/MockPsObjectModel.php @@ -4,6 +4,7 @@ namespace MyParcelNL\PrestaShop\Tests\Mock; +use MyParcelNL\Pdk\Base\Contract\Arrayable; use MyParcelNL\Pdk\Base\Support\Utils; use MyParcelNL\Sdk\src\Support\Str; use PrestaShop\PrestaShop\Core\Foundation\Database\EntityInterface; @@ -35,7 +36,7 @@ public function __construct(?int $id = null, ?int $id_lang = null, ?int $id_shop return; } - $this->hydrate($existing->toArray()); + $this->hydrate($existing->toArray(Arrayable::SKIP_NULL)); } } diff --git a/tests/Unit/Pdk/Installer/Service/PsInstallerServiceTest.php b/tests/Unit/Pdk/Installer/Service/PsInstallerServiceTest.php index ce2a7ac0..8bbfb782 100644 --- a/tests/Unit/Pdk/Installer/Service/PsInstallerServiceTest.php +++ b/tests/Unit/Pdk/Installer/Service/PsInstallerServiceTest.php @@ -7,11 +7,14 @@ namespace MyParcelNL\PrestaShop\Pdk\Installer\Service; +use Hook; +use MyParcelNL\Pdk\Base\Contract\Arrayable; +use MyParcelNL\Pdk\Base\Support\Collection; use MyParcelNL\Pdk\Facade\Installer; use MyParcelNL\Pdk\Facade\Pdk; use MyParcelNL\PrestaShop\Tests\Mock\MockPsDb; +use MyParcelNL\PrestaShop\Tests\Mock\MockPsObjectModels; use MyParcelNL\PrestaShop\Tests\Uses\UsesMockPlugin; -use MyParcelNL\Sdk\src\Support\Collection; use Tab; use function MyParcelNL\Pdk\Tests\usesShared; use function MyParcelNL\PrestaShop\psFactory; @@ -26,7 +29,7 @@ usesShared(new UsesMockPlugin()); -it('executes database migrations', function () { +it('installs: executes database migrations', function () { /** @var \MyParcelNL $module */ $module = Pdk::get('moduleInstance'); @@ -37,21 +40,32 @@ expect(MockPsDb::getDatabase())->toHaveKeys(MYPARCEL_TABLES); }); -it('installs tabs', function () { +it('installs: registers hooks', function () { + /** @var \MyParcelNL $module */ + $module = Pdk::get('moduleInstance'); + + expect(MockPsObjectModels::getByClass(Hook::class))->toBeEmpty(); + Installer::install($module); + + $createdHooks = MockPsObjectModels::getByClass(Hook::class); + + expect($createdHooks)->not->toBeEmpty(); + $this->assertMatchesJsonSnapshot(json_encode($createdHooks->toArray(Arrayable::SKIP_NULL))); +}); + +it('installs: installs tabs', function () { /** @var \MyParcelNL $module */ $module = Pdk::get('moduleInstance'); - /** @var \PrestaShopBundle\Entity\Repository\TabRepository $tabRepository */ - $tabRepository = Pdk::get('ps.tabRepository'); - expect($tabRepository->findAll())->toBeEmpty(); + expect(MockPsObjectModels::getByClass(Tab::class))->toBeEmpty(); Installer::install($module); $this->assertMatchesJsonSnapshot( - json_encode((new Collection($tabRepository->findByModule($module->name)))->toArray()) + json_encode((new Collection(MockPsObjectModels::getByClass(Tab::class)))->toArray(Arrayable::SKIP_NULL)) ); }); -it('doesn\'t add same tab twice', function () { +it('installs: doesn\'t add same tab twice', function () { /** @var \MyParcelNL $module */ $module = Pdk::get('moduleInstance'); /** @var \PrestaShopBundle\Entity\Repository\TabRepository $tabRepository */ diff --git a/tests/__snapshots__/PsInstallerServiceTest__it_installs_tabs__1.json b/tests/__snapshots__/PsInstallerServiceTest__it_installs_installs_tabs__1.json similarity index 75% rename from tests/__snapshots__/PsInstallerServiceTest__it_installs_tabs__1.json rename to tests/__snapshots__/PsInstallerServiceTest__it_installs_installs_tabs__1.json index 3dda314c..c5f676e6 100644 --- a/tests/__snapshots__/PsInstallerServiceTest__it_installs_tabs__1.json +++ b/tests/__snapshots__/PsInstallerServiceTest__it_installs_installs_tabs__1.json @@ -1,14 +1,11 @@ { "1": { - "id_lang": null, - "id_shop": null, "active": 1, "class_name": "MyParcelNLAdminSettings", "route_name": "myparcelnl_settings", "name": { "1": "MyParcelNL" }, - "id_parent": null, "module": "myparcelnl", "id": 1 } diff --git a/tests/__snapshots__/PsInstallerServiceTest__it_installs_registers_hooks__1.json b/tests/__snapshots__/PsInstallerServiceTest__it_installs_registers_hooks__1.json new file mode 100644 index 00000000..cdfbe7bc --- /dev/null +++ b/tests/__snapshots__/PsInstallerServiceTest__it_installs_registers_hooks__1.json @@ -0,0 +1,58 @@ +{ + "1": { + "name": "displayBeforeCarrier", + "id": 1 + }, + "2": { + "name": "displayCarrierExtraContent", + "id": 2 + }, + "3": { + "name": "actionCarrierProcess", + "id": 3 + }, + "4": { + "name": "actionOrderGridDefinitionModifier", + "id": 4 + }, + "5": { + "name": "actionOrderGridPresenterModifier", + "id": 5 + }, + "6": { + "name": "actionObjectCustomerMessageAddAfter", + "id": 6 + }, + "7": { + "name": "displayAdminOrderMain", + "id": 7 + }, + "8": { + "name": "actionProductUpdate", + "id": 8 + }, + "9": { + "name": "displayAdminProductsExtra", + "id": 9 + }, + "10": { + "name": "displayAdminAfterHeader", + "id": 10 + }, + "11": { + "name": "displayAdminEndContent", + "id": 11 + }, + "12": { + "name": "displayBackOfficeHeader", + "id": 12 + }, + "13": { + "name": "displayHeader", + "id": 13 + }, + "14": { + "name": "actionCarrierUpdate", + "id": 14 + } +} diff --git a/tests/mock_class_map.php b/tests/mock_class_map.php index 04d1e384..0b0cfec4 100644 --- a/tests/mock_class_map.php +++ b/tests/mock_class_map.php @@ -164,6 +164,11 @@ abstract class GroupCore extends ObjectModel { } final class Group extends GroupCore { } +/** @see \HookCore */ +abstract class HookCore extends ObjectModel { } + +final class Hook extends HookCore { } + /** @see \LangCore */ abstract class LangCore extends ObjectModel { }