From 9ac1c75cc5dad233ff47c441887375a7aa357da1 Mon Sep 17 00:00:00 2001 From: Hubert Filar Date: Mon, 2 Sep 2024 16:40:08 +0200 Subject: [PATCH] OP-289: Convert phpspec test to phpunit --- .github/workflows/build.yml | 3 - ...WhenEditNormalProductEventListenerSpec.php | 39 ------- ...WhenEditNormalProductEventListenerTest.php | 110 ++++++++++++++++++ 3 files changed, 110 insertions(+), 42 deletions(-) delete mode 100644 spec/EventListener/AddProductToProductBundleWhenEditNormalProductEventListenerSpec.php create mode 100644 tests/Unit/EventListener/AddProductToProductBundleWhenEditNormalProductEventListenerTest.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 509d94ee..41ac7541 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,9 +57,6 @@ jobs: - name: Validate database schema run: (cd tests/Application && bin/console doctrine:schema:validate) - - name: Run PHPSpec - run: vendor/bin/phpspec run --ansi -f progress --no-interaction - - name: Run PHPUnit run: vendor/bin/phpunit --colors=always diff --git a/spec/EventListener/AddProductToProductBundleWhenEditNormalProductEventListenerSpec.php b/spec/EventListener/AddProductToProductBundleWhenEditNormalProductEventListenerSpec.php deleted file mode 100644 index 84df86b7..00000000 --- a/spec/EventListener/AddProductToProductBundleWhenEditNormalProductEventListenerSpec.php +++ /dev/null @@ -1,39 +0,0 @@ -shouldHaveType(AddProductToProductBundleWhenEditNormalProductEventListener::class); - } - - public function it_should_add_product_to_product_bundle_if_not_exist_on_pre_create_and_update_event( - ResourceControllerEvent $resourceControllerEvent, - ProductInterface $product, - ProductBundleInterface $productBundle - ): void { - $resourceControllerEvent->getSubject()->willReturn($product); - - $product->getProductBundle()->shouldBeCalled(); - - $product->getProductBundle()->willReturn($productBundle); - - $this->addProductToProductBundle($resourceControllerEvent); - } -} diff --git a/tests/Unit/EventListener/AddProductToProductBundleWhenEditNormalProductEventListenerTest.php b/tests/Unit/EventListener/AddProductToProductBundleWhenEditNormalProductEventListenerTest.php new file mode 100644 index 00000000..7f8fb7ab --- /dev/null +++ b/tests/Unit/EventListener/AddProductToProductBundleWhenEditNormalProductEventListenerTest.php @@ -0,0 +1,110 @@ +instance = new AddProductToProductBundleWhenEditNormalProductEventListener(); + $this->resourceControllerEvent = $this->createMock(ResourceControllerEvent::class); + $this->product = $this->createMock(ProductInterface::class); + $this->productBundle = $this->createMock(ProductBundleInterface::class); + } + + public function testAddProductToProductBundle(): void + { + $this->productBundle + ->expects(self::once()) + ->method('getProduct') + ->willReturn(null); + + $this->product + ->expects(self::exactly(3)) + ->method('getProductBundle') + ->willReturn($this->productBundle); + + $this->productBundle + ->expects(self::once()) + ->method('setProduct') + ->with($this->product); + + $this->resourceControllerEvent + ->expects(self::once()) + ->method('getSubject') + ->willReturn($this->product); + + $this->instance->addProductToProductBundle($this->resourceControllerEvent); + } + + public function testWillNotAddProductToProductBundleIfProductHasBundle(): void + { + $this->productBundle + ->expects(self::never()) + ->method('getProduct'); + + $this->product + ->expects(self::once()) + ->method('getProductBundle') + ->willReturn(null); + + $this->productBundle + ->expects(self::never()) + ->method('setProduct'); + + $this->resourceControllerEvent + ->expects(self::once()) + ->method('getSubject') + ->willReturn($this->product); + + $this->instance->addProductToProductBundle($this->resourceControllerEvent); + } + + public function testWillNotAddProductToProductBundleIfProductBundleHasProduct(): void + { + $this->productBundle + ->expects(self::once()) + ->method('getProduct') + ->willReturn($this->product); + + $this->product + ->expects(self::exactly(2)) + ->method('getProductBundle') + ->willReturn($this->productBundle); + + $this->productBundle + ->expects(self::never()) + ->method('setProduct'); + + $this->resourceControllerEvent + ->expects(self::once()) + ->method('getSubject') + ->willReturn($this->product); + + $this->instance->addProductToProductBundle($this->resourceControllerEvent); + } +}