Skip to content
This repository was archived by the owner on Sep 25, 2022. It is now read-only.

Commit e8da86a

Browse files
committed
Reimplementation of the Extension to provide contexts out of the box.
1 parent bc86117 commit e8da86a

32 files changed

+1129
-172
lines changed

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
vendor
22
composer.lock
3-
test/SymfonyApp/cache
4-
test/SymfonyApp/logs
3+
tests/Functional/cache
4+
tests/Functional/logs
5+
coverage.xml
6+
.php_cs.cache

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ matrix:
2121
install:
2222
- composer self-update
2323
- composer install
24-
- rm -rf test/Features/SymfonyApp/cache/*
24+
- rm -rf tests/Features/Functional/cache/*
2525

2626
before_script:
2727
- bash -c 'php console doctrine:database:create --env=test'

behat.yml

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
default:
2+
autoload:
3+
'': %paths.base%/tests/Features/bootstrap
24
suites:
35
default:
4-
paths: [ %paths.base%/test/Features ]
6+
paths: [ %paths.base%/tests/Features ]
57
contexts:
6-
- Fidry\AliceFixturesExtension\Context\AliceContext:
7-
kernel: @kernel
8-
fixturesFinder: @hautelook_alice.doctrine.orm.fixtures_finder
9-
loader: @hautelook_alice.fixtures.loader
10-
persister: @doctrine.orm.entity_manager
11-
basePath: %paths.base%/test/Features/fixtures
8+
- FeatureContext
9+
- Fidry\AliceFixturesExtension\Context\Doctrine\AliceORMContext:
10+
basePath: %paths.base%/tests/Features/fixtures/ORM
1211

1312
extensions:
1413
Behat\Symfony2Extension:
1514
kernel:
1615
env: test
1716
debug: true
18-
path: test/SymfonyApp/AppKernel.php
19-
class: Fidry\AliceFixturesExtension\Tests\SymfonyApp\AppKernel
20-
bootstrap: test/SymfonyApp/autoload.php
21-
Fidry\AliceFixturesExtension\Extension: ~
17+
path: tests/Functional/AppKernel.php
18+
bootstrap: tests/Functional/autoload.php
19+
Fidry\AliceFixturesExtension\Extension:
20+
fixtures_base_path: %paths.base%/tests/Features/fixtures

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"doctrine/doctrine-bundle": "~1.2",
2323
"doctrine/doctrine-fixtures-bundle": "~2.2",
2424
"fabpot/php-cs-fixer": "~2.0@dev",
25+
"phpunit/phpunit": "^4.8",
2526
"symfony/console": "~2.1",
2627
"symfony/expression-language": "^2.7",
2728
"symfony/framework-bundle": "~2.1",
@@ -35,7 +36,7 @@
3536
},
3637
"autoload-dev": {
3738
"psr-4": {
38-
"Fidry\\AliceFixturesExtension\\Tests\\": "test"
39+
"Fidry\\AliceFixturesExtension\\Tests\\": "tests"
3940
}
4041
}
4142
}

console

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
set_time_limit(0);
1515

1616
require_once __DIR__.'/vendor/autoload.php';
17-
require_once __DIR__.'/test/SymfonyApp/autoload.php';
17+
require_once __DIR__.'/tests/Functional/autoload.php';
1818

1919
use Symfony\Bundle\FrameworkBundle\Console\Application;
2020
use Symfony\Component\Console\Input\ArgvInput;
@@ -30,6 +30,6 @@ if ($debug) {
3030

3131
error_reporting(E_ALL & ~E_USER_DEPRECATED);
3232

33-
$kernel = new Fidry\AliceFixturesExtension\Tests\SymfonyApp\AppKernel($env, $debug);
33+
$kernel = new AppKernel($env, $debug);
3434
$application = new Application($kernel);
3535
$application->run($input);

phpunit.xml.dist

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit colors="true" bootstrap="vendor/autoload.php" >
3+
4+
<logging>
5+
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true" />
6+
<log type="coverage-clover" target="coverage.xml" />
7+
</logging>
8+
9+
<testsuites>
10+
<testsuite name="AliceBundle Test Suite">
11+
<directory>./tests</directory>
12+
</testsuite>
13+
</testsuites>
14+
15+
<filter>
16+
<whitelist>
17+
<directory>.</directory>
18+
<exclude>
19+
<directory>vendor</directory>
20+
<directory>tests</directory>
21+
<directory>src/Resources</directory>
22+
</exclude>
23+
</whitelist>
24+
</filter>
25+
26+
</phpunit>

src/Context/AliceContext.php

+13-115
Original file line numberDiff line numberDiff line change
@@ -11,135 +11,33 @@
1111

1212
namespace Fidry\AliceFixturesExtension\Context;
1313

14-
use Behat\Behat\Context\Context;
15-
use Doctrine\Common\Persistence\ObjectManager;
16-
use Hautelook\AliceBundle\Alice\DataFixtures\LoaderInterface;
17-
use Hautelook\AliceBundle\Finder\FixturesFinderInterface;
18-
use Nelmio\Alice\Persister\Doctrine;
1914
use Nelmio\Alice\PersisterInterface;
20-
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
21-
use Symfony\Component\HttpKernel\KernelInterface;
2215

2316
/**
24-
* Context to load fixtures files with Alice loader.
25-
*
2617
* @author Théo FIDRY <[email protected]>
2718
*/
28-
class AliceContext implements Context
19+
interface AliceContext
2920
{
30-
/**
31-
* @var string
32-
*/
33-
private $basePath;
34-
35-
/**
36-
* @var FixturesFinderInterface
37-
*/
38-
private $fixturesFinder;
39-
40-
/**
41-
* @var KernelInterface
42-
*/
43-
private $kernel;
44-
45-
/**
46-
* @var LoaderInterface
47-
*/
48-
private $loader;
49-
50-
/**
51-
* @var PersisterInterface
52-
*/
53-
private $persister;
54-
55-
/**
56-
* @param KernelInterface $kernel
57-
* @param FixturesFinderInterface $fixturesFinder
58-
* @param LoaderInterface $loader
59-
* @param PersisterInterface|ObjectManager $persister
60-
* @param string $basePath
61-
*/
62-
public function __construct(
63-
KernelInterface $kernel,
64-
FixturesFinderInterface $fixturesFinder,
65-
LoaderInterface $loader,
66-
$persister,
67-
$basePath = null
68-
) {
69-
$this->kernel = $kernel;
70-
$this->fixturesFinder = $fixturesFinder;
71-
$this->loader = $loader;
72-
$this->persister = $this->resolvePersister($persister);
73-
$this->basePath = $basePath;
74-
}
75-
76-
/**
77-
* @Transform /^(\d+)$/
78-
*
79-
* @throws ServiceNotFoundException
80-
*/
81-
public function castServiceIdToService($serviceId)
82-
{
83-
return $this->kernel->getContainer()->get($serviceId);
84-
}
85-
86-
/**
87-
* @Transform /^(\d+)$/
88-
*
89-
* @throws ServiceNotFoundException
90-
*/
91-
public function castPersistence($serviceId)
92-
{
93-
$service = $this->castServiceIdToService($serviceId);
94-
95-
return $this->resolvePersister($service);
96-
}
97-
9821
/**
9922
* @Given the fixtures :fixturesFile are loaded
23+
* @Given the fixtures file :fixturesFile is loaded
10024
* @Given the fixtures :fixturesFile are loaded with the persister :persister
25+
* @Given the fixtures file :fixturesFile is loaded with the persister :persister
10126
*
102-
* @param string $fixturesFile Path to the fixtures
103-
* @param string $persister
104-
*
105-
* @return array
27+
* @param string $fixturesFile Path to the fixtures
28+
* @param PersisterInterface $persister
10629
*/
107-
public function thereAreFixtures($fixturesFile, $persister = null)
108-
{
109-
if (0 !== strpos($fixturesFile, '/') && 0 !== strpos($fixturesFile, '@')) {
110-
$fixturesFile = sprintf('%s/%s', $this->basePath, $fixturesFile);
111-
}
112-
113-
return $this->loader->load(
114-
$this->resolvePersister($persister),
115-
$this->fixturesFinder->resolveFixtures($this->kernel, [$fixturesFile])
116-
);
117-
}
30+
public function thereAreFixtures($fixturesFile, $persister = null);
11831

11932
/**
120-
* @param Doctrine|PersisterInterface|null $persister
33+
* @param string $basePath
12134
*
122-
* @return PersisterInterface
123-
*
124-
* @throws \InvalidArgumentException
35+
* @return $this
12536
*/
126-
private function resolvePersister($persister)
127-
{
128-
if (null === $persister) {
129-
return $this->persister;
130-
}
131-
132-
switch (true) {
133-
case $persister instanceof PersisterInterface:
134-
return $persister;
135-
case $persister instanceof ObjectManager:
136-
return new Doctrine($persister);
37+
public function setBasePath($basePath);
13738

138-
default:
139-
throw new \InvalidArgumentException(sprintf(
140-
'Invalid persister type, expected Nelmio\Alice\PersisterInterface or Doctrine\Common\Persistence\ObjectManager. Got %s instead.',
141-
get_class($persister)
142-
));
143-
}
144-
}
39+
/**
40+
* @return string
41+
*/
42+
public function getBasePath();
14543
}

0 commit comments

Comments
 (0)