Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -11,18 +11,32 @@
namespace Symfony\Component\HttpKernel\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
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\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest;
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelWithoutBundles;
use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;
class KernelTest extends \PHPUnit_Framework_TestCase
class KernelTest extends TestCase
{
public static function tearDownAfterClass()
{
$fs = new Filesystem();
$fs->remove(__DIR__.'/Fixtures/cache');
}
public function testConstructor()
{
$env = 'test_env';
@@ -51,6 +65,31 @@ class KernelTest extends \PHPUnit_Framework_TestCase
$this->assertNull($clone->getContainer());
}
public function testInitializeContainerClearsOldContainers()
{
$fs = new Filesystem();
$legacyContainerDir = __DIR__.'/Fixtures/cache/custom/ContainerA123456';
$fs->mkdir($legacyContainerDir);
touch($legacyContainerDir.'.legacy');
$kernel = new CustomProjectDirKernel();
$kernel->boot();
$containerDir = __DIR__.'/Fixtures/cache/custom/'.substr(\get_class($kernel->getContainer()), 0, 16);
$this->assertTrue(unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta'));
$this->assertFileExists($containerDir);
$this->assertFileNotExists($containerDir.'.legacy');
$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
$kernel->boot();
$this->assertFileExists($containerDir);
$this->assertFileExists($containerDir.'.legacy');
$this->assertFileNotExists($legacyContainerDir);
$this->assertFileNotExists($legacyContainerDir.'.legacy');
}
public function testBootInitializesBundlesAndContainer()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));
@@ -64,7 +103,7 @@ class KernelTest extends \PHPUnit_Framework_TestCase
public function testBootSetsTheContainerToTheBundles()
{
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
$bundle->expects($this->once())
->method('setContainer');
@@ -85,6 +124,9 @@ class KernelTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($kernel->isBooted());
}
/**
* @group legacy
*/
public function testClassCacheIsLoaded()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache'));
@@ -105,6 +147,9 @@ class KernelTest extends \PHPUnit_Framework_TestCase
$kernel->boot();
}
/**
* @group legacy
*/
public function testClassCacheIsNotLoadedWhenKernelIsNotBooted()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache'));
@@ -133,7 +178,7 @@ class KernelTest extends \PHPUnit_Framework_TestCase
->method('getLogDir')
->will($this->returnValue(sys_get_temp_dir()));
$reflection = new \ReflectionClass(get_class($kernel));
$reflection = new \ReflectionClass(\get_class($kernel));
$method = $reflection->getMethod('buildContainer');
$method->setAccessible(true);
$method->invoke($kernel);
@@ -161,7 +206,7 @@ class KernelTest extends \PHPUnit_Framework_TestCase
public function testShutdownCallsShutdownOnAllBundles()
{
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
$bundle->expects($this->once())
->method('shutdown');
@@ -173,7 +218,7 @@ class KernelTest extends \PHPUnit_Framework_TestCase
public function testShutdownGivesNullContainerToAllBundles()
{
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
$bundle->expects($this->at(3))
->method('setContainer')
->with(null);
@@ -304,7 +349,7 @@ EOF;
// Heredocs are preserved, making the output mixing Unix and Windows line
// endings, switching to "\n" everywhere on Windows to avoid failure.
if ('\\' === DIRECTORY_SEPARATOR) {
if ('\\' === \DIRECTORY_SEPARATOR) {
$expected = str_replace("\r\n", "\n", $expected);
$output = str_replace("\r\n", "\n", $output);
}
@@ -316,7 +361,7 @@ EOF;
{
$kernel = new KernelForTest('test', true);
$this->assertEquals(__DIR__.DIRECTORY_SEPARATOR.'Fixtures', realpath($kernel->getRootDir()));
$this->assertEquals(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures', realpath($kernel->getRootDir()));
}
public function testGetName()
@@ -394,6 +439,9 @@ EOF;
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1Bundle/foo.txt'));
}
/**
* @group legacy
*/
public function testLocateResourceReturnsTheFirstThatMatchesWithParent()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle');
@@ -410,6 +458,9 @@ EOF;
$this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/bar.txt', $kernel->locateResource('@ParentAABundle/bar.txt'));
}
/**
* @group legacy
*/
public function testLocateResourceReturnsAllMatches()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle');
@@ -428,6 +479,9 @@ EOF;
$kernel->locateResource('@Bundle1Bundle/foo.txt', null, false));
}
/**
* @group legacy
*/
public function testLocateResourceReturnsAllMatchesBis()
{
$kernel = $this->getKernel(array('getBundle'));
@@ -476,6 +530,9 @@ EOF;
);
}
/**
* @group legacy
*/
public function testLocateResourceReturnsTheDirOneForResourcesAndBundleOnes()
{
$kernel = $this->getKernel(array('getBundle'));
@@ -492,6 +549,9 @@ EOF;
);
}
/**
* @group legacy
*/
public function testLocateResourceOverrideBundleAndResourcesFolders()
{
$parent = $this->getBundle(__DIR__.'/Fixtures/BaseBundle', null, 'BaseBundle', 'BaseBundle');
@@ -565,6 +625,9 @@ EOF;
);
}
/**
* @group legacy
*/
public function testInitializeBundles()
{
$parent = $this->getBundle(null, null, 'ParentABundle');
@@ -583,6 +646,9 @@ EOF;
$this->assertEquals(array($child, $parent), $map['ParentABundle']);
}
/**
* @group legacy
*/
public function testInitializeBundlesSupportInheritanceCascade()
{
$grandparent = $this->getBundle(null, null, 'GrandParentBBundle');
@@ -605,6 +671,7 @@ EOF;
}
/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Bundle "ChildCBundle" extends bundle "FooBar", which is not registered.
*/
@@ -615,6 +682,9 @@ EOF;
$kernel->boot();
}
/**
* @group legacy
*/
public function testInitializeBundlesSupportsArbitraryBundleRegistrationOrder()
{
$grandparent = $this->getBundle(null, null, 'GrandParentCBundle');
@@ -637,6 +707,7 @@ EOF;
}
/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Bundle "ParentCBundle" is directly extended by two bundles "ChildC2Bundle" and "ChildC1Bundle".
*/
@@ -651,6 +722,7 @@ EOF;
}
/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Trying to register two bundles with the same name "DuplicateName"
*/
@@ -664,6 +736,7 @@ EOF;
}
/**
* @group legacy
* @expectedException \LogicException
* @expectedExceptionMessage Bundle "CircularRefBundle" can not extend itself.
*/
@@ -718,6 +791,131 @@ EOF;
$kernel->terminate(Request::create('/'), new Response());
}
public function testKernelWithoutBundles()
{
$kernel = new KernelWithoutBundles('test', true);
$kernel->boot();
$this->assertTrue($kernel->getContainer()->getParameter('test_executed'));
}
public function testKernelRootDirNameStartingWithANumber()
{
$dir = __DIR__.'/Fixtures/123';
require_once $dir.'/Kernel123.php';
$kernel = new \Symfony\Component\HttpKernel\Tests\Fixtures\_123\Kernel123('dev', true);
$this->assertEquals('_123', $kernel->getName());
}
/**
* @group legacy
* @expectedDeprecation The "Symfony\Component\HttpKernel\Kernel::getEnvParameters()" method is deprecated as of 3.3 and will be removed in 4.0. Use the %cenv()%c syntax to get the value of any environment variable from configuration files instead.
* @expectedDeprecation The support of special environment variables that start with SYMFONY__ (such as "SYMFONY__FOO__BAR") is deprecated as of 3.3 and will be removed in 4.0. Use the %cenv()%c syntax instead to get the value of environment variables in configuration files.
*/
public function testSymfonyEnvironmentVariables()
{
$_SERVER['SYMFONY__FOO__BAR'] = 'baz';
$kernel = $this->getKernel();
$method = new \ReflectionMethod($kernel, 'getEnvParameters');
$method->setAccessible(true);
$envParameters = $method->invoke($kernel);
$this->assertSame('baz', $envParameters['foo.bar']);
unset($_SERVER['SYMFONY__FOO__BAR']);
}
public function testProjectDirExtension()
{
$kernel = new CustomProjectDirKernel();
$kernel->boot();
$this->assertSame('foo', $kernel->getProjectDir());
$this->assertSame('foo', $kernel->getContainer()->getParameter('kernel.project_dir'));
}
public function testKernelReset()
{
(new Filesystem())->remove(__DIR__.'/Fixtures/cache');
$kernel = new CustomProjectDirKernel();
$kernel->boot();
$containerClass = \get_class($kernel->getContainer());
$containerFile = (new \ReflectionClass($kernel->getContainer()))->getFileName();
unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta');
$kernel = new CustomProjectDirKernel();
$kernel->boot();
$this->assertInstanceOf($containerClass, $kernel->getContainer());
$this->assertFileExists($containerFile);
unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta');
$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
$kernel->boot();
$this->assertNotInstanceOf($containerClass, $kernel->getContainer());
$this->assertFileExists($containerFile);
$this->assertFileExists(\dirname($containerFile).'.legacy');
}
public function testKernelPass()
{
$kernel = new PassKernel();
$kernel->boot();
$this->assertTrue($kernel->getContainer()->getParameter('test.processed'));
}
public function testServicesResetter()
{
$httpKernelMock = $this->getMockBuilder(HttpKernelInterface::class)
->disableOriginalConstructor()
->getMock();
$httpKernelMock
->expects($this->exactly(2))
->method('handle');
$kernel = new CustomProjectDirKernel(function ($container) {
$container->addCompilerPass(new ResettableServicePass());
$container->register('one', ResettableService::class)
->setPublic(true)
->addTag('kernel.reset', array('method' => 'reset'));
$container->register('services_resetter', ServicesResetter::class)->setPublic(true);
}, $httpKernelMock, 'resetting');
ResettableService::$counter = 0;
$request = new Request();
$kernel->handle($request);
$kernel->getContainer()->get('one');
$this->assertEquals(0, ResettableService::$counter);
$this->assertFalse($kernel->getContainer()->initialized('services_resetter'));
$kernel->handle($request);
$this->assertEquals(1, ResettableService::$counter);
}
/**
* @group time-sensitive
*/
public function testKernelStartTimeIsResetWhileBootingAlreadyBootedKernel()
{
$kernel = $this->getKernelForTest(array('initializeBundles'), true);
$kernel->boot();
$preReBoot = $kernel->getStartTime();
sleep(3600); //Intentionally large value to detect if ClockMock ever breaks
$kernel->reboot(null);
$this->assertGreaterThan($preReBoot, $kernel->getStartTime());
}
/**
* Returns a mock for the BundleInterface.
*
@@ -740,7 +938,7 @@ EOF;
$bundle
->expects($this->any())
->method('getName')
->will($this->returnValue(null === $bundleName ? get_class($bundle) : $bundleName))
->will($this->returnValue(null === $bundleName ? \get_class($bundle) : $bundleName))
;
$bundle
@@ -787,10 +985,10 @@ EOF;
return $kernel;
}
protected function getKernelForTest(array $methods = array())
protected function getKernelForTest(array $methods = array(), $debug = false)
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->setConstructorArgs(array('test', false))
->setConstructorArgs(array('test', $debug))
->setMethods($methods)
->getMock();
$p = new \ReflectionProperty($kernel, 'rootDir');
@@ -814,3 +1012,64 @@ class TestKernel implements HttpKernelInterface
{
}
}
class CustomProjectDirKernel extends Kernel
{
private $baseDir;
private $buildContainer;
private $httpKernel;
public function __construct(\Closure $buildContainer = null, HttpKernelInterface $httpKernel = null, $name = 'custom')
{
parent::__construct($name, true);
$this->baseDir = 'foo';
$this->buildContainer = $buildContainer;
$this->httpKernel = $httpKernel;
}
public function registerBundles()
{
return array();
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
}
public function getProjectDir()
{
return $this->baseDir;
}
public function getRootDir()
{
return __DIR__.'/Fixtures';
}
protected function build(ContainerBuilder $container)
{
if ($build = $this->buildContainer) {
$build($container);
}
}
protected function getHttpKernel()
{
return $this->httpKernel;
}
}
class PassKernel extends CustomProjectDirKernel implements CompilerPassInterface
{
public function __construct()
{
parent::__construct();
Kernel::__construct('pass', true);
}
public function process(ContainerBuilder $container)
{
$container->setParameter('test.processed', true);
}
}