Skip to content

Commit 5495d47

Browse files
committed
made behat work
1 parent e241a54 commit 5495d47

28 files changed

+387
-269
lines changed

behat.yml.dist

+37-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
11
imports:
2-
- vendor/sylius/sylius/behat.yml.dist
2+
- vendor/sylius/sylius/src/Sylius/Behat/Resources/config/suites.yml
33
- tests/Behat/Resources/suites.yml
44

55
default:
66
extensions:
7-
FriendsOfBehat\ContextServiceExtension:
8-
imports:
9-
- vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml
10-
- tests/Behat/Resources/services.yml
7+
Lakion\Behat\MinkDebugExtension:
8+
directory: etc/build
9+
clean_start: false
10+
screenshot: true
11+
12+
Behat\MinkExtension:
13+
files_path: "%paths.base%/vendor/sylius/sylius/src/Sylius/Behat/Resources/fixtures/"
14+
base_url: "http://localhost:8080/"
15+
default_session: symfony
16+
javascript_session: chrome
17+
sessions:
18+
symfony:
19+
symfony: ~
20+
chrome:
21+
selenium2:
22+
browser: chrome
23+
capabilities:
24+
browserName: chrome
25+
browser: chrome
26+
version: ""
27+
marionette: null # https://github.com/Behat/MinkExtension/pull/311
28+
chrome:
29+
switches:
30+
- "start-fullscreen"
31+
- "start-maximized"
32+
- "no-sandbox"
33+
firefox:
34+
selenium2:
35+
browser: firefox
36+
show_auto: false
1137

1238
FriendsOfBehat\SymfonyExtension:
13-
env_file: tests/Application/.env.test
39+
bootstrap: tests/Application/config/bootstrap.php
1440
kernel:
15-
env: test
16-
debug: true
1741
class: Tests\Setono\SyliusFacebookTrackingPlugin\Application\Kernel
18-
path: tests/Application/Kernel.php
19-
bootstrap: ~
2042

21-
Lakion\Behat\MinkDebugExtension:
22-
directory: etc/build
23-
clean_start: false
24-
screenshot: true
43+
FriendsOfBehat\VariadicExtension: ~
44+
45+
FriendsOfBehat\SuiteSettingsExtension:
46+
paths:
47+
- "features"

composer.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"thecodingmachine/safe": "^0.1.14"
1717
},
1818
"conflict": {
19+
"friends-of-behat/symfony-extension": ">=2.0.5 <= 2.0.8",
1920
"symfony/browser-kit": "4.1.8",
2021
"symfony/dependency-injection": "4.1.8",
2122
"symfony/dom-crawler": "4.1.8",
@@ -44,12 +45,12 @@
4445
"sensiolabs/security-checker": "^5.0",
4546
"setono/sylius-tag-bag-plugin": "^1.0",
4647
"sylius-labs/coding-standard": "^2.0",
47-
"symfony/browser-kit": "^3.4 || ^4.1",
48-
"symfony/debug-bundle": "^3.4 || ^4.1",
48+
"symfony/browser-kit": "^3.4|^4.1",
49+
"symfony/debug-bundle": "^3.4|^4.1",
4950
"symfony/dotenv": "^4.2",
50-
"symfony/intl": "^3.4 || ^4.1",
51-
"symfony/web-profiler-bundle": "^3.4 || ^4.1",
52-
"symfony/web-server-bundle": "^3.4 || ^4.1"
51+
"symfony/intl": "^3.4|^4.1",
52+
"symfony/web-profiler-bundle": "^3.4|^4.1",
53+
"symfony/web-server-bundle": "^3.4|^4.1"
5354
},
5455
"config": {
5556
"sort-packages": true

features/adding_facebook_config.feature

-16
This file was deleted.

features/admin/adding_pixel.feature

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@managing_pixels
2+
Feature: Adding a new pixel
3+
In order to use Facebook pixels for my website
4+
As an Administrator
5+
I want to add a new pixel
6+
7+
Background:
8+
Given I am logged in as an administrator
9+
And the store operates on a single channel in "United States"
10+
11+
@ui
12+
Scenario: Adding a new pixel
13+
Given I want to create a new pixel
14+
When I fill the pixel id with "123456789"
15+
And I add it
16+
Then I should be notified that it has been successfully created
17+
And the pixel "123456789" should appear in the store

features/admin/updating_pixel.feature

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@managing_pixels
2+
Feature: Updating a pixel
3+
In order to change pixel details
4+
As an Administrator
5+
I want to be able to edit a pixel
6+
7+
Background:
8+
Given the store has a pixel with pixel id "123456789"
9+
And I am logged in as an administrator
10+
And the store operates on a single channel in "United States"
11+
12+
@ui
13+
Scenario: Updating pixel id
14+
Given I want to update the pixel with pixel id "123456789"
15+
When I update the pixel with pixel id "123456789"
16+
And I save my changes
17+
Then I should be notified that it has been successfully edited
18+
And this pixel's pixel id should be "123456789"

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parameters:
77
reportUnmatchedIgnoredErrors: false
88

99
symfony:
10-
container_xml_path: tests/Application/var/cache/test/ApplicationTestDebugProjectContainer.xml
10+
container_xml_path: tests/Application/var/cache/test/ApplicationTests_Setono_SyliusFacebookTrackingPlugin_Application_KernelTestDebugContainer.xml
1111

1212
excludes_analyse:
1313
# Makes PHPStan crash

tests/Application/.env.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
APP_SECRET='ch4mb3r0f5ecr3ts'
22

3-
KERNEL_CLASS='Tests\Acme\SyliusExamplePlugin\Application\Kernel'
3+
KERNEL_CLASS='Tests\Setono\SyliusFacebookTrackingPlugin\Application\Kernel'

tests/Application/.eslintrc.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
module.exports = {
2-
extends: 'airbnb-base',
3-
env: {
4-
node: true,
5-
},
6-
rules: {
7-
'object-shorthand': ['error', 'always', {
8-
avoidQuotes: true,
9-
avoidExplicitReturnArrows: true,
10-
}],
11-
'function-paren-newline': ['error', 'consistent'],
12-
'max-len': ['warn', 120, 2, {
13-
ignoreUrls: true,
14-
ignoreComments: false,
15-
ignoreRegExpLiterals: true,
16-
ignoreStrings: true,
17-
ignoreTemplateLiterals: true,
18-
}],
19-
},
2+
extends: 'airbnb-base',
3+
env: {
4+
node: true,
5+
},
6+
rules: {
7+
'object-shorthand': ['error', 'always', {
8+
avoidQuotes: true,
9+
avoidExplicitReturnArrows: true,
10+
}],
11+
'function-paren-newline': ['error', 'consistent'],
12+
'max-len': ['warn', 120, 2, {
13+
ignoreUrls: true,
14+
ignoreComments: false,
15+
ignoreRegExpLiterals: true,
16+
ignoreStrings: true,
17+
ignoreTemplateLiterals: true,
18+
}],
19+
},
2020
};

tests/Application/Kernel.php

-68
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Tests\Setono\SyliusFacebookTrackingPlugin\Application;
66

7-
use ProxyManager\Proxy\VirtualProxyInterface;
87
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
98
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
109
use Symfony\Component\Config\Loader\DelegatingLoader;
@@ -31,13 +30,6 @@ final class Kernel extends BaseKernel
3130

3231
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
3332

34-
private const IGNORED_SERVICES_DURING_CLEANUP = [
35-
'kernel',
36-
'http_kernel',
37-
'liip_imagine.mime_type_guesser',
38-
'liip_imagine.extension_guesser',
39-
];
40-
4133
public function getCacheDir(): string
4234
{
4335
return $this->getProjectDir() . '/var/cache/' . $this->environment;
@@ -58,25 +50,6 @@ public function registerBundles(): iterable
5850
}
5951
}
6052

61-
public function shutdown(): void
62-
{
63-
if (!$this->isTestEnvironment()) {
64-
parent::shutdown();
65-
66-
return;
67-
}
68-
69-
if (false === $this->booted) {
70-
return;
71-
}
72-
73-
$container = $this->getContainer();
74-
75-
parent::shutdown();
76-
77-
$this->cleanupContainer($container);
78-
}
79-
8053
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
8154
{
8255
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
@@ -130,45 +103,4 @@ private function isTestEnvironment(): bool
130103
{
131104
return 0 === strpos($this->getEnvironment(), 'test');
132105
}
133-
134-
/**
135-
* Remove all container references from all loaded services
136-
*/
137-
private function cleanupContainer(ContainerInterface $container): void
138-
{
139-
$containerReflection = new \ReflectionObject($container);
140-
$containerServicesPropertyReflection = $containerReflection->getProperty('services');
141-
$containerServicesPropertyReflection->setAccessible(true);
142-
143-
$services = $containerServicesPropertyReflection->getValue($container) ?: [];
144-
foreach ($services as $serviceId => $service) {
145-
if (null === $service) {
146-
continue;
147-
}
148-
149-
if (in_array($serviceId, self::IGNORED_SERVICES_DURING_CLEANUP, true)) {
150-
continue;
151-
}
152-
153-
$serviceReflection = new \ReflectionObject($service);
154-
155-
if ($serviceReflection->implementsInterface(VirtualProxyInterface::class)) {
156-
continue;
157-
}
158-
159-
$servicePropertiesReflections = $serviceReflection->getProperties();
160-
$servicePropertiesDefaultValues = $serviceReflection->getDefaultProperties();
161-
foreach ($servicePropertiesReflections as $servicePropertyReflection) {
162-
$defaultPropertyValue = null;
163-
if (isset($servicePropertiesDefaultValues[$servicePropertyReflection->getName()])) {
164-
$defaultPropertyValue = $servicePropertiesDefaultValues[$servicePropertyReflection->getName()];
165-
}
166-
167-
$servicePropertyReflection->setAccessible(true);
168-
$servicePropertyReflection->setValue($service, $defaultPropertyValue);
169-
}
170-
}
171-
172-
$containerServicesPropertyReflection->setValue($container, null);
173-
}
174106
}

tests/Application/config/bundles.php

+1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@
5858
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
5959
Setono\TagBagBundle\SetonoTagBagBundle::class => ['all' => true],
6060
Setono\SyliusTagBagPlugin\SetonoSyliusTagBagPlugin::class => ['all' => true],
61+
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
6162
];
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Setono\SyliusFacebookTrackingPlugin\Behat\Context\Setup;
6+
7+
use Behat\Behat\Context\Context;
8+
use Setono\SyliusFacebookTrackingPlugin\Model\PixelInterface;
9+
use Setono\SyliusFacebookTrackingPlugin\Repository\PixelRepositoryInterface;
10+
use Sylius\Component\Resource\Factory\FactoryInterface;
11+
12+
final class PixelContext implements Context
13+
{
14+
/**
15+
* @var PixelRepositoryInterface
16+
*/
17+
private $pixelRepository;
18+
19+
/**
20+
* @var FactoryInterface
21+
*/
22+
private $pixelFactory;
23+
24+
public function __construct(PixelRepositoryInterface $pixelRepository, FactoryInterface $pixelFactory)
25+
{
26+
$this->pixelRepository = $pixelRepository;
27+
$this->pixelFactory = $pixelFactory;
28+
}
29+
30+
/**
31+
* @Given the store has a pixel with pixel id :pixelId
32+
*/
33+
public function theStoreHasAPropertyWithTrackingId($pixelId): void
34+
{
35+
$obj = $this->createProperty($pixelId);
36+
37+
$this->save($obj);
38+
}
39+
40+
private function createProperty(string $pixelId): PixelInterface
41+
{
42+
/** @var PixelInterface $obj */
43+
$obj = $this->pixelFactory->createNew();
44+
45+
$obj->setPixelId($pixelId);
46+
47+
return $obj;
48+
}
49+
50+
private function save(PixelInterface $pixel): void
51+
{
52+
$this->pixelRepository->add($pixel);
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Setono\SyliusFacebookTrackingPlugin\Behat\Context\Transform;
6+
7+
use Behat\Behat\Context\Context;
8+
use Setono\SyliusFacebookTrackingPlugin\Repository\PixelRepositoryInterface;
9+
10+
final class PixelContext implements Context
11+
{
12+
/**
13+
* @var PixelRepositoryInterface
14+
*/
15+
private $pixelRepository;
16+
17+
public function __construct(PixelRepositoryInterface $pixelRepository)
18+
{
19+
$this->pixelRepository = $pixelRepository;
20+
}
21+
22+
/**
23+
* @Transform :pixel
24+
*/
25+
public function getPixelByPixelId($pixel)
26+
{
27+
return $this->pixelRepository->findOneBy([
28+
'pixelId' => $pixel
29+
]);
30+
}
31+
}

0 commit comments

Comments
 (0)