Skip to content

Commit

Permalink
Merge pull request #527 from alexislefebvre/2.x-revert-feature/cherry…
Browse files Browse the repository at this point in the history
…-pick-4.3

2.x revert feature/cherry pick 4.3
  • Loading branch information
alexislefebvre authored Jun 14, 2019
2 parents 464c7a2 + 100a6b3 commit 7b4e401
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 118 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ matrix:
env: EXTRA_PACKAGES="doctrine/phpcr-bundle:^1.3 brianium/paratest:^1.0 doctrine/phpcr-odm:^1.3"
- php: 7.3
env: SYMFONY_VERSION="^4.1"
- php: 7.3
env: SYMFONY_VERSION="^4.3"
allow_failures:
- php: 7.2
env: SYMFONY_VERSION="dev-master"
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"theofidry/alice-data-fixtures": "^1.0.1",
"twig/twig": "^2.0"
},
"conflict": {
"symfony/framework-bundle": "4.3.0"
},
"suggest": {
"brianium/paratest": "Required when using paratest to parallelize tests",
"doctrine/dbal": "Required when using the fixture loading functionality with an ORM and SQLite",
Expand Down
6 changes: 0 additions & 6 deletions src/DependencyInjection/Compiler/SetTestClientPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ public function process(ContainerBuilder $container): void
$definition = $container->getDefinition('test.client');
$definition->setPublic(false);
$container->setDefinition('liip_functional_test.query.count_client.parent', $definition);
} elseif ($container->hasAlias('test.client')) {
// Symfony <2.8
$container->setAlias(
'liip_functional_test.query.count_client.parent',
new Alias((string) $container->getAlias('test.client'), false)
);
} else {
throw new \Exception('The LiipFunctionalTestBundle\'s Query Counter can only be used in the test environment.'.PHP_EOL.'See https://github.com/liip/LiipFunctionalTestBundle#only-in-test-environment');
}
Expand Down
8 changes: 7 additions & 1 deletion src/QueryCountClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@

use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;

// Symfony <4 BC
if (class_exists(CompilerDebugDumpPass::class)) {
class_alias(QueryCountClientSymfony3Trait::class, QueryCountClientTrait::class);
}

class QueryCountClient extends Client
// Symfony <4.3.1 BC
if (!class_exists(KernelBrowser::class)) {
class_alias(Client::class, KernelBrowser::class);
}

class QueryCountClient extends KernelBrowser
{
/*
* We use trait only because of Client::request signature strict type mismatch between Symfony 3 and 4.
Expand Down
10 changes: 1 addition & 9 deletions src/Test/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
*/
abstract class WebTestCase extends BaseWebTestCase
{
/** @var Client|null */
protected static $client;

protected $environment = 'test';

protected $containers;
Expand Down Expand Up @@ -413,7 +410,7 @@ protected function makeClient($authentication = false, array $params = []): Clie
$session->save();
}

return static::$client = $client;
return $client;
}

/**
Expand Down Expand Up @@ -571,8 +568,3 @@ protected function tearDown(): void
parent::tearDown();
}
}

// Compatibility layer for Symfony 4.3+
if (class_exists('Symfony\Bundle\FrameworkBundle\KernelBrowser')) {
class_alias('Symfony\Bundle\FrameworkBundle\KernelBrowser', 'Symfony\Bundle\FrameworkBundle\Client');
}
32 changes: 1 addition & 31 deletions tests/DependencyInjection/Compiler/SetTestClientPassMockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,6 @@
*/
class SetTestClientPassMockTest extends TestCase
{
/**
* Simulate Symfony 2.8.
*/
public function testSetTestClientPassHasAlias(): void
{
/* @see http://gianarb.it/blog/symfony-unit-test-controller-with-phpunit#expectations */
/** @var \Symfony\Component\DependencyInjection\ContainerBuilder $container */
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
->getMock();

$container->expects($this->any())
->method('getParameter')
->will($this->returnValue(true));

$container->expects($this->any())
->method('hasDefinition')
->will($this->returnValue(false));

$container->expects($this->once())
->method('hasAlias')
->will($this->returnValue(true));

$container->expects($this->exactly(2))
->method('setAlias')
->will($this->returnValue(true));

$setTestClientPass = new SetTestClientPass($container);
$setTestClientPass->process($container);
}

/**
* Simulate a wrong environment.
*/
Expand All @@ -78,7 +48,7 @@ public function testSetTestClientPassElse(): void
->will($this->returnValue(false));

try {
$setTestClientPass = new SetTestClientPass($container);
$setTestClientPass = new SetTestClientPass();
$setTestClientPass->process($container);
} catch (\Exception $e) {
$this->assertSame(
Expand Down
4 changes: 2 additions & 2 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ConfigurationTest extends WebTestCase

public function setUp(): void
{
static::$client = $this->makeClient();
$this->clientContainer = static::$client->getContainer();
$client = static::makeClient();
$this->clientContainer = $client->getContainer();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Test/WebTestCaseConfigLeanFrameworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected static function getKernelClass(): string

public function testAssertStatusCode(): void
{
$client = $this->makeClient();
$client = static::makeClient();

$path = '/';
$client->request('GET', $path);
Expand All @@ -45,7 +45,7 @@ public function testAssertStatusCode(): void

public function testAssertValidationErrorsTriggersError(): void
{
$client = $this->makeClient();
$client = static::makeClient();

$path = '/form';
$client->request('GET', $path);
Expand Down
30 changes: 17 additions & 13 deletions tests/Test/WebTestCaseConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
*/
class WebTestCaseConfigTest extends WebTestCase
{
/** @var \Symfony\Bundle\FrameworkBundle\Client client */
private $client = null;

protected static function getKernelClass(): string
{
return AppConfigKernel::class;
Expand All @@ -48,16 +51,16 @@ public function testIndexAuthenticationArray(): void
{
$this->loadFixtures([]);

static::$client = $this->makeClient([
$this->client = static::makeClient([
'username' => 'foobar',
'password' => '12341234',
]);

$path = '/';

$crawler = static::$client->request('GET', $path);
$crawler = $this->client->request('GET', $path);

$this->assertStatusCode(200, static::$client);
$this->assertStatusCode(200, $this->client);

$this->assertSame(1,
$crawler->filter('html > body')->count());
Expand All @@ -82,13 +85,13 @@ public function testIndexAuthenticationTrue(): void
{
$this->loadFixtures([]);

static::$client = $this->makeClient(true);
$this->client = static::makeClient(true);

$path = '/';

$crawler = static::$client->request('GET', $path);
$crawler = $this->client->request('GET', $path);

$this->assertStatusCode(200, static::$client);
$this->assertStatusCode(200, $this->client);

$this->assertSame(1,
$crawler->filter('html > body')->count());
Expand Down Expand Up @@ -124,13 +127,13 @@ public function testIndexAuthenticationLoginAs(): void
$loginAs
);

static::$client = $this->makeClient();
$this->client = static::makeClient();

$path = '/';

$crawler = static::$client->request('GET', $path);
$crawler = $this->client->request('GET', $path);

$this->assertStatusCode(200, static::$client);
$this->assertStatusCode(200, $this->client);

$this->assertSame(1,
$crawler->filter('html > body')->count());
Expand Down Expand Up @@ -168,12 +171,12 @@ public function testAllowedQueriesExceededException(): void
$this->loginAs($repository->getReference('user'),
'secured_area');

static::$client = $this->makeClient();
$this->client = static::makeClient();

// One another query to load the second user.
$path = '/user/2';

static::$client->request('GET', $path);
$this->client->request('GET', $path);
}

/**
Expand All @@ -191,12 +194,13 @@ public function testAnnotationAndException(): void
$this->loadFixtures([
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData',
]);
static::$client = $this->makeClient();

$this->client = static::makeClient();

// One query to load the second user
$path = '/user/1';

static::$client->request('GET', $path);
$this->client->request('GET', $path);
}

/**
Expand Down
Loading

0 comments on commit 7b4e401

Please sign in to comment.