minor #33428 Cleanup tests (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

Cleanup tests

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

a461943345 Cleanup tests
This commit is contained in:
Nicolas Grekas 2019-09-02 16:39:16 +02:00
commit 33e466577f
5 changed files with 29 additions and 39 deletions

View File

@ -354,7 +354,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
{
if (null === $this->projectDir) {
$r = new \ReflectionObject($this);
$dir = $rootDir = \dirname($r->getFileName());
if (!file_exists($dir = $r->getFileName())) {
throw new \LogicException(sprintf('Cannot auto-detect project dir for kernel of class "%s".', $r->name));
}
$dir = $rootDir = \dirname($dir);
while (!file_exists($dir.'/composer.json')) {
if ($dir === \dirname($dir)) {
return $this->projectDir = $rootDir;

View File

@ -34,4 +34,9 @@ class KernelForTest extends Kernel
{
return $this->booted;
}
public function getProjectDir()
{
return __DIR__;
}
}

View File

@ -22,7 +22,6 @@ use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName;
@ -119,7 +118,7 @@ class KernelTest extends TestCase
public function testBootSetsTheBootedFlagToTrue()
{
// use test kernel to access isBooted()
$kernel = $this->getKernelForTest(['initializeBundles', 'initializeContainer']);
$kernel = $this->getKernel(['initializeBundles', 'initializeContainer']);
$kernel->boot();
$this->assertTrue($kernel->isBooted());
@ -899,7 +898,7 @@ EOF;
*/
public function testKernelStartTimeIsResetWhileBootingAlreadyBootedKernel()
{
$kernel = $this->getKernelForTest(['initializeBundles'], true);
$kernel = $this->getKernel(['initializeBundles'], [], true);
$kernel->boot();
$preReBoot = $kernel->getStartTime();
@ -957,15 +956,15 @@ EOF;
*
* @return Kernel
*/
protected function getKernel(array $methods = [], array $bundles = [])
protected function getKernel(array $methods = [], array $bundles = [], $debug = false)
{
$methods[] = 'registerBundles';
$kernel = $this
->getMockBuilder('Symfony\Component\HttpKernel\Kernel')
->getMockBuilder(KernelForTest::class)
->setMethods($methods)
->setConstructorArgs(['test', false])
->getMockForAbstractClass()
->setConstructorArgs(['test', $debug])
->getMock()
;
$kernel->expects($this->any())
->method('registerBundles')
@ -980,10 +979,11 @@ EOF;
protected function getKernelForTest(array $methods = [], $debug = false)
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
$kernel = $this->getMockBuilder(KernelForTest::class)
->setConstructorArgs(['test', $debug])
->setMethods($methods)
->getMock();
->getMock()
;
$p = new \ReflectionProperty($kernel, 'rootDir');
$p->setAccessible(true);
$p->setValue($kernel, __DIR__.'/Fixtures');
@ -1004,6 +1004,11 @@ class TestKernel implements HttpKernelInterface
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
}
public function getProjectDir()
{
return __DIR__.'/Fixtures';
}
}
class CustomProjectDirKernel extends Kernel

View File

@ -30,6 +30,10 @@ trait BlockingStoreTestTrait
*
* This test is time sensible: the $clockDelay could be adjust.
*
* It also fails when run with the global ./phpunit test suite.
*
* @group transient
*
* @requires extension pcntl
* @requires extension posix
* @requires function pcntl_sigwaitinfo

View File

@ -84,23 +84,6 @@ class ChainEncoderTest extends TestCase
$this->assertTrue($this->chainEncoder->needsNormalization(self::FORMAT_2));
}
/**
* @dataProvider booleanProvider
*/
public function testNeedsNormalizationChainNormalizationAware($bool)
{
$chainEncoder = $this
->getMockBuilder('Symfony\Component\Serializer\Tests\Encoder\ChainNormalizationAwareEncoder')
->getMock();
$chainEncoder->method('supportsEncoding')->willReturn(true);
$chainEncoder->method('needsNormalization')->willReturn($bool);
$sut = new ChainEncoder([$chainEncoder]);
$this->assertEquals($bool, $sut->needsNormalization(self::FORMAT_1));
}
public function testNeedsNormalizationNormalizationAware()
{
$encoder = new NormalizationAwareEncoder();
@ -108,18 +91,6 @@ class ChainEncoderTest extends TestCase
$this->assertFalse($sut->needsNormalization(self::FORMAT_1));
}
public function booleanProvider()
{
return [
[true],
[false],
];
}
}
class ChainNormalizationAwareEncoder extends ChainEncoder implements NormalizationAwareInterface
{
}
class NormalizationAwareEncoder implements EncoderInterface, NormalizationAwareInterface