From 2735b28eb5de2e82ff22bbd879cd6ad49b62045e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20K=C3=BChnel?= Date: Mon, 1 Jul 2019 15:21:57 +0200 Subject: [PATCH 1/2] behat tests --- README.md | 21 ++++---- behat.yml.dist | 1 + composer.json | 3 -- ..._orders_for_certain_payment_method.feature | 50 +++++++++++-------- .../download_current_exchange_rates.feature | 10 ++-- .../send_order_email_to_bcc_email.feature | 6 +-- features/set_bcc_email_to_channel.feature | 6 +-- features/set_phone_to_channel.feature | 6 +-- features/set_timezone_to_channel.feature | 6 +-- ...roduct_prices_using_exchange_rates.feature | 11 ++-- phpstan.neon | 3 ++ phpunit.xml.dist | 27 +++++----- tests/Application/.gitignore | 7 +-- .../config/packages/test/framework.yaml | 3 ++ tests/Application/public/index.php | 41 +++++++++++++++ tests/Application/public/media/image/.gitkeep | 0 tests/Behat/Context/Domain/CommandContext.php | 12 ++--- 17 files changed, 130 insertions(+), 83 deletions(-) create mode 100644 tests/Application/public/index.php create mode 100644 tests/Application/public/media/image/.gitkeep diff --git a/README.md b/README.md index 77d6995..9c088b9 100644 --- a/README.md +++ b/README.md @@ -76,18 +76,15 @@ Run `src/Migrations/basic-data/timezones-data.sql` for load the timezones table. ### Testing After your changes you must ensure that the tests are still passing. -* Easy Coding Standard - ```bash - bin/ecs.sh - ``` -* PHPStan - ```bash - bin/phpstan.sh - ``` -* Behat - ```bash - bin/behat - ``` + +```bash +$ composer install +$ bin/console doctrine:schema:create -e test +$ bin/behat +$ bin/phpstan.sh +$ bin/ecs.sh +``` + License ------- This library is under the MIT license. diff --git a/behat.yml.dist b/behat.yml.dist index 9c0adfe..919050a 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -14,6 +14,7 @@ default: class: \App\Kernel path: tests/Application/src/Kernel.php bootstrap: vendor/autoload.php + env: test Behat\MinkExtension: base_url: "http://localhost:8000/" diff --git a/composer.json b/composer.json index a6058e1..07a35a5 100644 --- a/composer.json +++ b/composer.json @@ -49,8 +49,5 @@ "branch-alias": { "dev-master": "1.2-dev" } - }, - "config": { - "bin-dir": "bin" } } diff --git a/features/cancel_unpaid_orders_for_certain_payment_method.feature b/features/cancel_unpaid_orders_for_certain_payment_method.feature index 6414187..5f4957b 100644 --- a/features/cancel_unpaid_orders_for_certain_payment_method.feature +++ b/features/cancel_unpaid_orders_for_certain_payment_method.feature @@ -1,8 +1,8 @@ @cancel_unpaid_orders_for_certain_payment_method Feature: Cancel unpaid orders for certain payment method - As a administrator / cron - Remove orders that are not paid for a configured period and for certain shipping methods. - This allows to keep unpaid orders which are e.g. to be paid at personal pickup, therefore needs to stay unpaid for a couple of hours / days + In order to cancel unpaid orders which is too old for certain payment method + As an Administrator + I want to cancel orders that are not paid for a configured period and for certain shipping methods Background: Given the store operates on a single channel in "United States" @@ -12,46 +12,54 @@ Feature: Cancel unpaid orders for certain payment method And the store has "DHL" shipping method with "$5.00" fee And the store allows paying with "Cash on Delivery" And the store also allows paying with "CSOB" - And the guest customer placed order with number "00000001" with "Screwdriver" product for "john+1@snow.com" and "United States" based shipping address with "DHL" shipping method and "CSOB" payment - And this order is "3" days old - And the guest customer placed order with number "00000002" with "Screwdriver" product for "john+2@snow.com" and "United States" based shipping address with "DHL" shipping method and "Cash on Delivery" payment - And this order is "3" days old - And the guest customer placed order with number "00000003" with "Screwdriver" product for "john+3@snow.com" and "United States" based shipping address with "DHL" shipping method and "CSOB" payment - And this order is "1" days old - And the guest customer placed order with number "00000004" with "Screwdriver" product for "john+4@snow.com" and "United States" based shipping address with "DHL" shipping method and "Cash on Delivery" payment - And this order is "1" days old - And the guest customer placed order with number "00000005" with "Screwdriver" product for "john+5@snow.com" and "United States" based shipping address with "DHL" shipping method and "CSOB" payment - And this order is already paid - And this order is "3" days old - And I run command to cancellation orders - And I am logged in as an administrator @ui Scenario: The order will be canceled, older than limit and payment allowed canceling + Given the guest customer placed order with number "00000001" with "Screwdriver" product for "john+1@snow.com" and "United States" based shipping address with "DHL" shipping method and "CSOB" payment + And this order is "3" days old + And I cancel orders + And I am logged in as an administrator When I view the summary of the order "00000001" - And its state should be "Cancelled" + Then its state should be "Cancelled" And it should have payment state "Cancelled" @ui Scenario: The order wont be canceled, older than limit and payment not allowed canceling + Given the guest customer placed order with number "00000002" with "Screwdriver" product for "john+2@snow.com" and "United States" based shipping address with "DHL" shipping method and "Cash on Delivery" payment + And this order is "3" days old + And I cancel orders + And I am logged in as an administrator When I view the summary of the order "00000002" - And its state should be "New" + Then its state should be "New" And it should have payment state "New" @ui Scenario: The order wont be canceled, younger than limit and payment allowed canceling + Given the guest customer placed order with number "00000003" with "Screwdriver" product for "john+3@snow.com" and "United States" based shipping address with "DHL" shipping method and "CSOB" payment + And this order is "1" days old + And I cancel orders + And I am logged in as an administrator When I view the summary of the order "00000003" - And its state should be "New" + Then its state should be "New" And it should have payment state "New" @ui Scenario: The order wont be canceled, younger than limit and payment not allowed canceling + Given the guest customer placed order with number "00000004" with "Screwdriver" product for "john+4@snow.com" and "United States" based shipping address with "DHL" shipping method and "Cash on Delivery" payment + And this order is "1" days old + And I cancel orders + And I am logged in as an administrator When I view the summary of the order "00000004" - And its state should be "New" + Then its state should be "New" And it should have payment state "New" @ui Scenario: The order wont be canceled, already paid + Given the guest customer placed order with number "00000005" with "Screwdriver" product for "john+5@snow.com" and "United States" based shipping address with "DHL" shipping method and "CSOB" payment + And this order is already paid + And this order is "3" days old + And I cancel orders + And I am logged in as an administrator When I view the summary of the order "00000005" - And its state should be "New" + Then its state should be "New" And it should have payment state "Completed" diff --git a/features/download_current_exchange_rates.feature b/features/download_current_exchange_rates.feature index 400c854..3266fa1 100644 --- a/features/download_current_exchange_rates.feature +++ b/features/download_current_exchange_rates.feature @@ -1,8 +1,8 @@ @download_current_exchange_rates Feature: Download current exchange rates and update it - As a administrator / cron - Download current exchange rates - Update exchange rates + In order to update local exchange rates by live exchange rates + As an Administrator + Download current exchange rates and update it Background: Given the store has currency "EUR" @@ -11,5 +11,5 @@ Feature: Download current exchange rates and update it @ui Scenario: Run the command and download and update exchange rates - Given I run command to update exchange rates - And the exchange rate of "EUR" to "GBP" should be 0.88225 + Given I update exchange rates + Then the exchange rate of "EUR" to "GBP" should be 0.88225 diff --git a/features/send_order_email_to_bcc_email.feature b/features/send_order_email_to_bcc_email.feature index 82e987a..b331cc6 100644 --- a/features/send_order_email_to_bcc_email.feature +++ b/features/send_order_email_to_bcc_email.feature @@ -1,8 +1,8 @@ @send_order_email_to_bcc_email Feature: Send an order email to bcc email - In order to be able to send an order email to bcc email - As a Administrator - I want to receive an order email when customer finish order + In order to be able to send an copy of order email to bcc email + As an Administrator + I want to receive an copy of order email when customer finish order Background: Given the store operates on a single channel in "United States" diff --git a/features/set_bcc_email_to_channel.feature b/features/set_bcc_email_to_channel.feature index d92b6a9..4f5fc68 100644 --- a/features/set_bcc_email_to_channel.feature +++ b/features/set_bcc_email_to_channel.feature @@ -1,8 +1,8 @@ @managing_channel -Feature: Set bcc email to channel - Add a bcc email to the channel in administration for email send copy of email to it. +Feature: Set bcc email for channel + In order to add a bcc email to channel settings in admin panel As an Administrator - I want to set bcc email to the channel + I want to set the bcc email on the channel details page Background: Given the store operates on a channel named "Mango Channel" diff --git a/features/set_phone_to_channel.feature b/features/set_phone_to_channel.feature index ded8025..a5217fd 100644 --- a/features/set_phone_to_channel.feature +++ b/features/set_phone_to_channel.feature @@ -1,8 +1,8 @@ @managing_channel -Feature: Set phone number to channel - Add a phone number to the channel in administration (for email, footer, etc.) +Feature: Set phone number for channel + In order to add a phone number to channel settings in admin panel As an Administrator - I want to set a phone number to the channel + I want to set the phone number on the channel details page Background: Given the store operates on a channel named "Mango Channel" diff --git a/features/set_timezone_to_channel.feature b/features/set_timezone_to_channel.feature index 1b1813a..b5886d8 100644 --- a/features/set_timezone_to_channel.feature +++ b/features/set_timezone_to_channel.feature @@ -1,8 +1,8 @@ @managing_channel -Feature: Set timezone to channel - Add a timezone to the channel in administration. +Feature: Set timezone for channel + In order to add a timezone to channel settings in admin panel As an Administrator - I want to set timezone to the channel + I want to set the timezone on the channel details page Background: Given the store operates on a channel named "Mango Channel" diff --git a/features/update_product_prices_using_exchange_rates.feature b/features/update_product_prices_using_exchange_rates.feature index 39e02d2..2dc5ec5 100644 --- a/features/update_product_prices_using_exchange_rates.feature +++ b/features/update_product_prices_using_exchange_rates.feature @@ -1,7 +1,8 @@ @update_product_prices_using_exchange_rates -Feature: Update product prices using exchange rates - As a administrator / cron - Update product prices using exchange rates +Feature: Update product prices on another channel using exchange rates + In order to update product price on another channel using exchange rates + As an Administrator + I want to be able to update product prices using exchange rates Background: Given the store has currency "EUR" @@ -15,6 +16,6 @@ Feature: Update product prices using exchange rates @ui Scenario: Run comman and check prices - Given I run command to update product prices on channels "Web-EU" and "Web-GB" - And check that the product "Screwdriver" has price "€10.00" on channel "Web-EU" + Given I update product prices on channels "Web-EU" and "Web-GB" + Then check that the product "Screwdriver" has price "€10.00" on channel "Web-EU" And check that the product "Screwdriver" has price "€12.00" on channel "Web-GB" diff --git a/phpstan.neon b/phpstan.neon index 9b4b2b7..cbf4dc5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -13,3 +13,6 @@ parameters: # Test dependencies - '*/tests/Application/var/*' + + - 'src/Service/SwiftMailerAdapter.php' + - 'tests/Behat/Context/Ui/Shop/OrderContext.php' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9023d3a..56e97ba 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,19 @@ - - - tests - - + xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.6/phpunit.xsd" + backupGlobals="false" + colors="true" + bootstrap="vendor/autoload.php"> + + + tests + + - - - - + + + + + diff --git a/tests/Application/.gitignore b/tests/Application/.gitignore index 8951026..d2ac1c1 100644 --- a/tests/Application/.gitignore +++ b/tests/Application/.gitignore @@ -1,6 +1,7 @@ ###> symfony/framework-bundle ### /public/bundles/ +/public/assets/ /var/ /vendor/ ###< symfony/framework-bundle ### @@ -17,10 +18,4 @@ .env /node_modules/ -/public/* -!/public/assets/.gitkeep -!/public/bundles/.gitkeep !/public/media/image/.gitkeep -!/public/app.php -!/public/app_dev.php -!/public/app_test.php diff --git a/tests/Application/config/packages/test/framework.yaml b/tests/Application/config/packages/test/framework.yaml index d051c84..b268537 100644 --- a/tests/Application/config/packages/test/framework.yaml +++ b/tests/Application/config/packages/test/framework.yaml @@ -2,3 +2,6 @@ framework: test: true session: storage_id: session.storage.mock_file + +parameters: + env(APP_SECRET): 'dsf65g4sy65fv4y64' diff --git a/tests/Application/public/index.php b/tests/Application/public/index.php new file mode 100644 index 0000000..522f32a --- /dev/null +++ b/tests/Application/public/index.php @@ -0,0 +1,41 @@ +load(__DIR__ . '/../.env'); +} + +$env = $_SERVER['APP_ENV'] ?? 'dev'; +$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ($env !== 'prod')); + +if ($debug) { + umask(0000); + + Debug::enable(); +} + +if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) { + Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); +} + +if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) { + Request::setTrustedHosts(explode(',', $trustedHosts)); +} + +$kernel = new Kernel($env, $debug); +$request = Request::createFromGlobals(); +$response = $kernel->handle($request); +$response->send(); +$kernel->terminate($request, $response); diff --git a/tests/Application/public/media/image/.gitkeep b/tests/Application/public/media/image/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Behat/Context/Domain/CommandContext.php b/tests/Behat/Context/Domain/CommandContext.php index c51f681..6eff902 100644 --- a/tests/Behat/Context/Domain/CommandContext.php +++ b/tests/Behat/Context/Domain/CommandContext.php @@ -25,9 +25,9 @@ public function __construct( } /** - * @Given I run command to update product prices on channels :arg1 and :arg2 + * @Given I update product prices on channels :arg1 and :arg2 */ - public function iRunCommandToUpdateProductPricesOnChannelsAnd(string $arg1, string $arg2) + public function iUpdateProductPricesOnChannelsAnd(string $arg1, string $arg2) { $application = new Application($this->kernel); $application->add(new InstallSampleDataCommand()); @@ -40,9 +40,9 @@ public function iRunCommandToUpdateProductPricesOnChannelsAnd(string $arg1, stri } /** - * @Given I run command to cancellation orders + * @Given I cancel orders */ - public function iRunCommandToCancellationOrders() + public function iCancelOrders() { $application = new Application($this->kernel); $application->add(new InstallSampleDataCommand()); @@ -52,9 +52,9 @@ public function iRunCommandToCancellationOrders() } /** - * @Given I run command to update exchange rates + * @Given I update exchange rates */ - public function iRunCommandToUpdateExchangeRates() + public function iUpdateExchangeRates() { $application = new Application($this->kernel); $application->add(new InstallSampleDataCommand()); From 406a927b4fe9b997330e14ccc3c7076996076593 Mon Sep 17 00:00:00 2001 From: Johan Hornof Date: Tue, 2 Jul 2019 14:14:56 +0200 Subject: [PATCH 2/2] changelog update --- CHANGELOG-0.3.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG-0.3.md b/CHANGELOG-0.3.md index c412ed5..1751669 100644 --- a/CHANGELOG-0.3.md +++ b/CHANGELOG-0.3.md @@ -5,3 +5,10 @@ #### Details - Behat tests + +## v0.3.1 (2019-07-02) + +#### Details + +- Better tests +