Skip to content

Commit

Permalink
Merge pull request #2 from mangoweb-sylius/pr/behat
Browse files Browse the repository at this point in the history
Pr/behat
  • Loading branch information
Johan Hornof authored Jul 2, 2019
2 parents 1b29d45 + 406a927 commit f158205
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 83 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG-0.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
#### Details

- Behat tests

## v0.3.1 (2019-07-02)

#### Details

- Better tests

21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,5 @@
"branch-alias": {
"dev-master": "1.2-dev"
}
},
"config": {
"bin-dir": "bin"
}
}
50 changes: 29 additions & 21 deletions features/cancel_unpaid_orders_for_certain_payment_method.feature
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 "[email protected]" 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 "[email protected]" 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 "[email protected]" 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 "[email protected]" 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 "[email protected]" 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 "[email protected]" 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 "[email protected]" 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 "[email protected]" 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 "[email protected]" 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 "[email protected]" 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"
10 changes: 5 additions & 5 deletions features/download_current_exchange_rates.feature
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
6 changes: 3 additions & 3 deletions features/send_order_email_to_bcc_email.feature
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions features/set_bcc_email_to_channel.feature
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions features/set_phone_to_channel.feature
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions features/set_timezone_to_channel.feature
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 6 additions & 5 deletions features/update_product_prices_using_exchange_rates.feature
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ parameters:

# Test dependencies
- '*/tests/Application/var/*'

- 'src/Service/SwiftMailerAdapter.php'
- 'tests/Behat/Context/Ui/Shop/OrderContext.php'
27 changes: 14 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.6/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="AcmeSyliusExamplePlugin Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.6/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="AcmeSyliusExamplePlugin Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<php>
<server name="KERNEL_CLASS_PATH" value="/tests/Application/src/Kernel.php" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
</php>
<php>
<server name="KERNEL_CLASS_PATH" value="/tests/Application/src/Kernel.php"/>
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true"/>
<env name="APP_SECRET" value="''"/>
</php>
</phpunit>
7 changes: 1 addition & 6 deletions tests/Application/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

###> symfony/framework-bundle ###
/public/bundles/
/public/assets/
/var/
/vendor/
###< symfony/framework-bundle ###
Expand All @@ -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
3 changes: 3 additions & 0 deletions tests/Application/config/packages/test/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ framework:
test: true
session:
storage_id: session.storage.mock_file

parameters:
env(APP_SECRET): 'dsf65g4sy65fv4y64'
41 changes: 41 additions & 0 deletions tests/Application/public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;

require __DIR__ . '/../../../vendor/autoload.php';

// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
if (!class_exists(Dotenv::class)) {
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}
(new Dotenv())->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);
Empty file.
12 changes: 6 additions & 6 deletions tests/Behat/Context/Domain/CommandContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit f158205

Please sign in to comment.