Added Laravel project

This commit is contained in:
2017-09-17 00:35:10 +02:00
parent a3c19304d5
commit ecf605b8f5
6246 changed files with 682270 additions and 2 deletions

View File

@@ -0,0 +1,120 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use PHPUnit\Framework\TestCase;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedChildClass;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedClass;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedImplementor;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedInterface;
/**
* @covers \SebastianBergmann\GlobalState\Blacklist
*/
class BlacklistTest extends TestCase
{
/**
* @var \SebastianBergmann\GlobalState\Blacklist
*/
private $blacklist;
protected function setUp()
{
$this->blacklist = new Blacklist;
}
public function testGlobalVariableThatIsNotBlacklistedIsNotTreatedAsBlacklisted()
{
$this->assertFalse($this->blacklist->isGlobalVariableBlacklisted('variable'));
}
public function testGlobalVariableCanBeBlacklisted()
{
$this->blacklist->addGlobalVariable('variable');
$this->assertTrue($this->blacklist->isGlobalVariableBlacklisted('variable'));
}
public function testStaticAttributeThatIsNotBlacklistedIsNotTreatedAsBlacklisted()
{
$this->assertFalse(
$this->blacklist->isStaticAttributeBlacklisted(
BlacklistedClass::class,
'attribute'
)
);
}
public function testClassCanBeBlacklisted()
{
$this->blacklist->addClass(BlacklistedClass::class);
$this->assertTrue(
$this->blacklist->isStaticAttributeBlacklisted(
BlacklistedClass::class,
'attribute'
)
);
}
public function testSubclassesCanBeBlacklisted()
{
$this->blacklist->addSubclassesOf(BlacklistedClass::class);
$this->assertTrue(
$this->blacklist->isStaticAttributeBlacklisted(
BlacklistedChildClass::class,
'attribute'
)
);
}
public function testImplementorsCanBeBlacklisted()
{
$this->blacklist->addImplementorsOf(BlacklistedInterface::class);
$this->assertTrue(
$this->blacklist->isStaticAttributeBlacklisted(
BlacklistedImplementor::class,
'attribute'
)
);
}
public function testClassNamePrefixesCanBeBlacklisted()
{
$this->blacklist->addClassNamePrefix('SebastianBergmann\GlobalState');
$this->assertTrue(
$this->blacklist->isStaticAttributeBlacklisted(
BlacklistedClass::class,
'attribute'
)
);
}
public function testStaticAttributeCanBeBlacklisted()
{
$this->blacklist->addStaticAttribute(
BlacklistedClass::class,
'attribute'
);
$this->assertTrue(
$this->blacklist->isStaticAttributeBlacklisted(
BlacklistedClass::class,
'attribute'
)
);
}
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use PHPUnit\Framework\TestCase;
/**
* @covers \SebastianBergmann\GlobalState\CodeExporter
*/
class CodeExporterTest extends TestCase
{
/**
* @runInSeparateProcess
*/
public function testCanExportGlobalVariablesToCode()
{
$GLOBALS = ['foo' => 'bar'];
$snapshot = new Snapshot(null, true, false, false, false, false, false, false, false, false);
$exporter = new CodeExporter;
$this->assertEquals(
'$GLOBALS = [];' . PHP_EOL . '$GLOBALS[\'foo\'] = \'bar\';' . PHP_EOL,
$exporter->globalVariables($snapshot)
);
}
}

View File

@@ -0,0 +1,105 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use PHPUnit\Framework\TestCase;
/**
* Class Restorer.
*/
class RestorerTest extends TestCase
{
public static function setUpBeforeClass()
{
$GLOBALS['varBool'] = false;
$GLOBALS['varNull'] = null;
$_GET['varGet'] = 0;
}
/**
* Check global variables are correctly backuped and restored (unit test).
*
* @covers \SebastianBergmann\GlobalState\Restorer::restoreGlobalVariables
* @covers \SebastianBergmann\GlobalState\Restorer::restoreSuperGlobalArray
*
* @uses \SebastianBergmann\GlobalState\Blacklist::isGlobalVariableBlacklisted
* @uses \SebastianBergmann\GlobalState\Snapshot::__construct
* @uses \SebastianBergmann\GlobalState\Snapshot::blacklist
* @uses \SebastianBergmann\GlobalState\Snapshot::canBeSerialized
* @uses \SebastianBergmann\GlobalState\Snapshot::globalVariables
* @uses \SebastianBergmann\GlobalState\Snapshot::setupSuperGlobalArrays
* @uses \SebastianBergmann\GlobalState\Snapshot::snapshotGlobals
* @uses \SebastianBergmann\GlobalState\Snapshot::snapshotSuperGlobalArray
* @uses \SebastianBergmann\GlobalState\Snapshot::superGlobalArrays
* @uses \SebastianBergmann\GlobalState\Snapshot::superGlobalVariables
*/
public function testRestorerGlobalVariable()
{
$snapshot = new Snapshot(null, true, false, false, false, false, false, false, false, false);
$restorer = new Restorer;
$restorer->restoreGlobalVariables($snapshot);
$this->assertArrayHasKey('varBool', $GLOBALS);
$this->assertEquals(false, $GLOBALS['varBool']);
$this->assertArrayHasKey('varNull', $GLOBALS);
$this->assertEquals(null, $GLOBALS['varNull']);
$this->assertArrayHasKey('varGet', $_GET);
$this->assertEquals(0, $_GET['varGet']);
}
/**
* Check global variables are correctly backuped and restored.
*
* The real test is the second, but the first has to be executed to backup the globals.
*
* @backupGlobals enabled
* @covers \SebastianBergmann\GlobalState\Restorer::restoreGlobalVariables
* @covers \SebastianBergmann\GlobalState\Restorer::restoreSuperGlobalArray
*
* @uses \SebastianBergmann\GlobalState\Blacklist::addClassNamePrefix
* @uses \SebastianBergmann\GlobalState\Blacklist::isGlobalVariableBlacklisted
* @uses \SebastianBergmann\GlobalState\Snapshot::__construct
* @uses \SebastianBergmann\GlobalState\Snapshot::blacklist
* @uses \SebastianBergmann\GlobalState\Snapshot::canBeSerialized
* @uses \SebastianBergmann\GlobalState\Snapshot::globalVariables
* @uses \SebastianBergmann\GlobalState\Snapshot::setupSuperGlobalArrays
* @uses \SebastianBergmann\GlobalState\Snapshot::snapshotGlobals
* @uses \SebastianBergmann\GlobalState\Snapshot::snapshotSuperGlobalArray
* @uses \SebastianBergmann\GlobalState\Snapshot::superGlobalArrays
* @uses \SebastianBergmann\GlobalState\Snapshot::superGlobalVariables
*/
public function testIntegrationRestorerGlobalVariables()
{
$this->assertArrayHasKey('varBool', $GLOBALS);
$this->assertEquals(false, $GLOBALS['varBool']);
$this->assertArrayHasKey('varNull', $GLOBALS);
$this->assertEquals(null, $GLOBALS['varNull']);
$this->assertArrayHasKey('varGet', $_GET);
$this->assertEquals(0, $_GET['varGet']);
}
/**
* Check global variables are correctly backuped and restored.
*
* @depends testIntegrationRestorerGlobalVariables
*/
public function testIntegrationRestorerGlobalVariables2()
{
$this->assertArrayHasKey('varBool', $GLOBALS);
$this->assertEquals(false, $GLOBALS['varBool']);
$this->assertArrayHasKey('varNull', $GLOBALS);
$this->assertEquals(null, $GLOBALS['varNull']);
$this->assertArrayHasKey('varGet', $_GET);
$this->assertEquals(0, $_GET['varGet']);
}
}

View File

@@ -0,0 +1,116 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState;
use ArrayObject;
use PHPUnit\Framework\TestCase;
use SebastianBergmann\GlobalState\TestFixture\BlacklistedInterface;
use SebastianBergmann\GlobalState\TestFixture\SnapshotClass;
use SebastianBergmann\GlobalState\TestFixture\SnapshotTrait;
/**
* @covers \SebastianBergmann\GlobalState\Snapshot
*/
class SnapshotTest extends TestCase
{
/**
* @var Blacklist
*/
private $blacklist;
protected function setUp()
{
$this->blacklist = $this->createMock(Blacklist::class);
}
public function testStaticAttributes()
{
$this->blacklist->method('isStaticAttributeBlacklisted')->willReturnCallback(
function ($class) {
return $class !== SnapshotClass::class;
}
);
SnapshotClass::init();
$snapshot = new Snapshot($this->blacklist, false, true, false, false, false, false, false, false, false);
$expected = [
SnapshotClass::class => [
'string' => 'snapshot',
'arrayObject' => new ArrayObject([1, 2, 3]),
'stdClass' => new \stdClass(),
]
];
$this->assertEquals($expected, $snapshot->staticAttributes());
}
public function testConstants()
{
$snapshot = new Snapshot($this->blacklist, false, false, true, false, false, false, false, false, false);
$this->assertArrayHasKey('GLOBALSTATE_TESTSUITE', $snapshot->constants());
}
public function testFunctions()
{
$snapshot = new Snapshot($this->blacklist, false, false, false, true, false, false, false, false, false);
$functions = $snapshot->functions();
$this->assertContains('sebastianbergmann\globalstate\testfixture\snapshotfunction', $functions);
$this->assertNotContains('assert', $functions);
}
public function testClasses()
{
$snapshot = new Snapshot($this->blacklist, false, false, false, false, true, false, false, false, false);
$classes = $snapshot->classes();
$this->assertContains(TestCase::class, $classes);
$this->assertNotContains(Exception::class, $classes);
}
public function testInterfaces()
{
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, true, false, false, false);
$interfaces = $snapshot->interfaces();
$this->assertContains(BlacklistedInterface::class, $interfaces);
$this->assertNotContains(\Countable::class, $interfaces);
}
public function testTraits()
{
\spl_autoload_call('SebastianBergmann\GlobalState\TestFixture\SnapshotTrait');
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, true, false, false);
$this->assertContains(SnapshotTrait::class, $snapshot->traits());
}
public function testIniSettings()
{
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, false, true, false);
$iniSettings = $snapshot->iniSettings();
$this->assertArrayHasKey('date.timezone', $iniSettings);
$this->assertEquals('Etc/UTC', $iniSettings['date.timezone']);
}
public function testIncludedFiles()
{
$snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, false, false, true);
$this->assertContains(__FILE__, $snapshot->includedFiles());
}
}

View File

@@ -0,0 +1,17 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
class BlacklistedChildClass extends BlacklistedClass
{
}

View File

@@ -0,0 +1,18 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
class BlacklistedClass
{
private static $attribute;
}

View File

@@ -0,0 +1,18 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
class BlacklistedImplementor implements BlacklistedInterface
{
private static $attribute;
}

View File

@@ -0,0 +1,17 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
interface BlacklistedInterface
{
}

View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
use DomDocument;
use ArrayObject;
class SnapshotClass
{
private static $string = 'snapshot';
private static $dom;
private static $closure;
private static $arrayObject;
private static $snapshotDomDocument;
private static $resource;
private static $stdClass;
public static function init()
{
self::$dom = new DomDocument();
self::$closure = function () {};
self::$arrayObject = new ArrayObject([1, 2, 3]);
self::$snapshotDomDocument = new SnapshotDomDocument();
self::$resource = \fopen('php://memory', 'r');
self::$stdClass = new \stdClass();
}
}

View File

@@ -0,0 +1,19 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
use DomDocument;
class SnapshotDomDocument extends DomDocument
{
}

View File

@@ -0,0 +1,17 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
function snapshotFunction()
{
}

View File

@@ -0,0 +1,17 @@
<?php
/*
* This file is part of sebastian/global-state.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SebastianBergmann\GlobalState\TestFixture;
trait SnapshotTrait
{
}