mirror of
https://0xacab.org/radar/radar-wp.git
synced 2025-04-23 16:26:29 +02:00
Initial import.
This commit is contained in:
commit
86383280c9
428 changed files with 68738 additions and 0 deletions
130
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/ChainDriverTest.php
vendored
Normal file
130
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/ChainDriverTest.php
vendored
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
|
||||
use Doctrine\Tests\DoctrineTestCase;
|
||||
|
||||
class DriverChainTest extends DoctrineTestCase
|
||||
{
|
||||
public function testDelegateToMatchingNamespaceDriver()
|
||||
{
|
||||
$className = 'Doctrine\Tests\Common\Persistence\Mapping\DriverChainEntity';
|
||||
$classMetadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
|
||||
|
||||
$chain = new MappingDriverChain();
|
||||
|
||||
$driver1 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||
$driver1->expects($this->never())
|
||||
->method('loadMetadataForClass');
|
||||
$driver1->expectS($this->never())
|
||||
->method('isTransient');
|
||||
|
||||
$driver2 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||
$driver2->expects($this->at(0))
|
||||
->method('loadMetadataForClass')
|
||||
->with($this->equalTo($className), $this->equalTo($classMetadata));
|
||||
$driver2->expects($this->at(1))
|
||||
->method('isTransient')
|
||||
->with($this->equalTo($className))
|
||||
->will($this->returnValue( true ));
|
||||
|
||||
$chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
|
||||
$chain->addDriver($driver2, 'Doctrine\Tests\Common\Persistence\Mapping');
|
||||
|
||||
$chain->loadMetadataForClass($className, $classMetadata);
|
||||
|
||||
$this->assertTrue( $chain->isTransient($className) );
|
||||
}
|
||||
|
||||
public function testLoadMetadata_NoDelegatorFound_ThrowsMappingException()
|
||||
{
|
||||
$className = 'Doctrine\Tests\Common\Persistence\Mapping\DriverChainEntity';
|
||||
$classMetadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
|
||||
|
||||
$chain = new MappingDriverChain();
|
||||
|
||||
$this->setExpectedException('Doctrine\Common\Persistence\Mapping\MappingException');
|
||||
$chain->loadMetadataForClass($className, $classMetadata);
|
||||
}
|
||||
|
||||
public function testGatherAllClassNames()
|
||||
{
|
||||
$className = 'Doctrine\Tests\Common\Persistence\Mapping\DriverChainEntity';
|
||||
$classMetadata = $this->getMock('Doctrine\Common\Peristence\ClassMetadata');
|
||||
|
||||
$chain = new MappingDriverChain();
|
||||
|
||||
$driver1 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||
$driver1->expects($this->once())
|
||||
->method('getAllClassNames')
|
||||
->will($this->returnValue(array('Doctrine\Tests\Models\Company\Foo')));
|
||||
|
||||
$driver2 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||
$driver2->expects($this->once())
|
||||
->method('getAllClassNames')
|
||||
->will($this->returnValue(array('Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz')));
|
||||
|
||||
$chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
|
||||
$chain->addDriver($driver2, 'Doctrine\Tests\ORM\Mapping');
|
||||
|
||||
$this->assertEquals(array(
|
||||
'Doctrine\Tests\Models\Company\Foo',
|
||||
'Doctrine\Tests\ORM\Mapping\Bar',
|
||||
'Doctrine\Tests\ORM\Mapping\Baz'
|
||||
), $chain->getAllClassNames());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-706
|
||||
*/
|
||||
public function testIsTransient()
|
||||
{
|
||||
$driver1 = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||
$chain = new MappingDriverChain();
|
||||
$chain->addDriver($driver1, 'Doctrine\Tests\Models\CMS');
|
||||
|
||||
$this->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1412
|
||||
*/
|
||||
public function testDefaultDriver()
|
||||
{
|
||||
$companyDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||
$dafaultDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||
$entityClassName = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
|
||||
$managerClassName = 'Doctrine\Tests\Models\Company\CompanyManager';
|
||||
$chain = new MappingDriverChain();
|
||||
|
||||
$companyDriver->expects($this->never())
|
||||
->method('loadMetadataForClass');
|
||||
$companyDriver->expects($this->once())
|
||||
->method('isTransient')
|
||||
->with($this->equalTo($managerClassName))
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$dafaultDriver->expects($this->never())
|
||||
->method('loadMetadataForClass');
|
||||
$dafaultDriver->expects($this->once())
|
||||
->method('isTransient')
|
||||
->with($this->equalTo($entityClassName))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertNull($chain->getDefaultDriver());
|
||||
|
||||
$chain->setDefaultDriver($dafaultDriver);
|
||||
$chain->addDriver($companyDriver, 'Doctrine\Tests\Models\Company');
|
||||
|
||||
$this->assertSame($dafaultDriver, $chain->getDefaultDriver());
|
||||
|
||||
$this->assertTrue($chain->isTransient($entityClassName));
|
||||
$this->assertFalse($chain->isTransient($managerClassName));
|
||||
}
|
||||
}
|
||||
|
||||
class DriverChainEntity
|
||||
{
|
||||
|
||||
}
|
139
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/ClassMetadataFactoryTest.php
vendored
Normal file
139
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/ClassMetadataFactoryTest.php
vendored
Normal file
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Tests\DoctrineTestCase;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator;
|
||||
use Doctrine\Common\Persistence\Mapping\ReflectionService;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
|
||||
class ClassMetadataFactoryTest extends DoctrineTestCase
|
||||
{
|
||||
/**
|
||||
* @var TestClassMetadataFactory
|
||||
*/
|
||||
private $cmf;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
|
||||
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
|
||||
$this->cmf = new TestClassMetadataFactory($driver, $metadata);
|
||||
}
|
||||
|
||||
public function testGetCacheDriver()
|
||||
{
|
||||
$this->assertNull($this->cmf->getCacheDriver());
|
||||
$cache = new ArrayCache();
|
||||
$this->cmf->setCacheDriver($cache);
|
||||
$this->assertSame($cache, $this->cmf->getCacheDriver());
|
||||
}
|
||||
|
||||
public function testGetMetadataFor()
|
||||
{
|
||||
$metadata = $this->cmf->getMetadataFor('stdClass');
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Persistence\Mapping\ClassMetadata', $metadata);
|
||||
$this->assertTrue($this->cmf->hasMetadataFor('stdClass'));
|
||||
}
|
||||
|
||||
public function testGetParentMetadata()
|
||||
{
|
||||
$metadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
|
||||
|
||||
$this->assertInstanceOf('Doctrine\Common\Persistence\Mapping\ClassMetadata', $metadata);
|
||||
$this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\ChildEntity'));
|
||||
$this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\RootEntity'));
|
||||
}
|
||||
|
||||
public function testGetCachedMetadata()
|
||||
{
|
||||
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
|
||||
$cache = new ArrayCache();
|
||||
$cache->save(__NAMESPACE__. '\ChildEntity$CLASSMETADATA', $metadata);
|
||||
|
||||
$this->cmf->setCacheDriver($cache);
|
||||
|
||||
$loadedMetadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
|
||||
$this->assertSame($loadedMetadata, $metadata);
|
||||
}
|
||||
|
||||
public function testCacheGetMetadataFor()
|
||||
{
|
||||
$cache = new ArrayCache();
|
||||
$this->cmf->setCacheDriver($cache);
|
||||
|
||||
$loadedMetadata = $this->cmf->getMetadataFor(__NAMESPACE__ . '\ChildEntity');
|
||||
|
||||
$this->assertSame($loadedMetadata, $cache->fetch(__NAMESPACE__. '\ChildEntity$CLASSMETADATA'));
|
||||
}
|
||||
|
||||
public function testGetAliasedMetadata()
|
||||
{
|
||||
$loadedMetadata = $this->cmf->getMetadataFor('prefix:ChildEntity');
|
||||
|
||||
$this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\ChildEntity'));
|
||||
$this->assertTrue($this->cmf->hasMetadataFor('prefix:ChildEntity'));
|
||||
}
|
||||
}
|
||||
|
||||
class TestClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
{
|
||||
public $driver;
|
||||
public $metadata;
|
||||
|
||||
public function __construct($driver, $metadata)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
|
||||
protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
|
||||
{
|
||||
return __NAMESPACE__ . '\\' . $simpleClassName;
|
||||
}
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function newClassMetadataInstance($className)
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
protected function getDriver()
|
||||
{
|
||||
return $this->driver;
|
||||
}
|
||||
protected function wakeupReflection(ClassMetadata $class, ReflectionService $reflService)
|
||||
{
|
||||
}
|
||||
|
||||
protected function initializeReflection(ClassMetadata $class, ReflectionService $reflService)
|
||||
{
|
||||
}
|
||||
|
||||
protected function isEntity(ClassMetadata $class)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class RootEntity
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class ChildEntity extends RootEntity
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Tests\DoctrineTestCase;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator;
|
||||
|
||||
class DefaultFileLocatorTest extends DoctrineTestCase
|
||||
{
|
||||
public function testGetPaths()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
|
||||
$locator = new DefaultFileLocator(array($path));
|
||||
$this->assertEquals(array($path), $locator->getPaths());
|
||||
|
||||
$locator = new DefaultFileLocator($path);
|
||||
$this->assertEquals(array($path), $locator->getPaths());
|
||||
}
|
||||
|
||||
public function testGetFileExtension()
|
||||
{
|
||||
$locator = new DefaultFileLocator(array(), ".yml");
|
||||
$this->assertEquals(".yml", $locator->getFileExtension());
|
||||
$locator->setFileExtension(".xml");
|
||||
$this->assertEquals(".xml", $locator->getFileExtension());
|
||||
}
|
||||
|
||||
public function testUniquePaths()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
|
||||
$locator = new DefaultFileLocator(array($path, $path));
|
||||
$this->assertEquals(array($path), $locator->getPaths());
|
||||
}
|
||||
|
||||
public function testFindMappingFile()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
|
||||
$locator = new DefaultFileLocator(array($path), ".yml");
|
||||
|
||||
$this->assertEquals(__DIR__ . '/_files' . DIRECTORY_SEPARATOR . 'stdClass.yml', $locator->findMappingFile('stdClass'));
|
||||
}
|
||||
|
||||
public function testFindMappingFileNotFound()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
|
||||
$locator = new DefaultFileLocator(array($path), ".yml");
|
||||
|
||||
$this->setExpectedException(
|
||||
'Doctrine\Common\Persistence\Mapping\MappingException',
|
||||
"No mapping file found named 'stdClass2.yml' for class 'stdClass2'"
|
||||
);
|
||||
$locator->findMappingFile('stdClass2');
|
||||
}
|
||||
|
||||
public function testGetAllClassNames()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
|
||||
$locator = new DefaultFileLocator(array($path), ".yml");
|
||||
$classes = $locator->getAllClassNames(null);
|
||||
sort($classes);
|
||||
|
||||
$this->assertEquals(array('global', 'stdClass'), $classes);
|
||||
$this->assertEquals(array('stdClass'), $locator->getAllClassNames("global"));
|
||||
}
|
||||
|
||||
public function testGetAllClassNamesNonMatchingFileExtension()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
|
||||
$locator = new DefaultFileLocator(array($path), ".xml");
|
||||
$this->assertEquals(array(), $locator->getAllClassNames("global"));
|
||||
}
|
||||
|
||||
public function testFileExists()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
|
||||
$locator = new DefaultFileLocator(array($path), ".yml");
|
||||
|
||||
$this->assertTrue($locator->fileExists("stdClass"));
|
||||
$this->assertFalse($locator->fileExists("stdClass2"));
|
||||
$this->assertTrue($locator->fileExists("global"));
|
||||
$this->assertFalse($locator->fileExists("global2"));
|
||||
}
|
||||
}
|
142
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/FileDriverTest.php
vendored
Normal file
142
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/FileDriverTest.php
vendored
Normal file
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Tests\DoctrineTestCase;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
|
||||
class FileDriverTest extends DoctrineTestCase
|
||||
{
|
||||
public function testGlobalBasename()
|
||||
{
|
||||
$driver = new TestFileDriver(array());
|
||||
|
||||
$this->assertNull($driver->getGlobalBasename());
|
||||
|
||||
$driver->setGlobalBasename("global");
|
||||
$this->assertEquals("global", $driver->getGlobalBasename());
|
||||
}
|
||||
|
||||
public function testGetElementFromGlobalFile()
|
||||
{
|
||||
$driver = new TestFileDriver($this->newLocator());
|
||||
$driver->setGlobalBasename("global");
|
||||
|
||||
$element = $driver->getElement('stdGlobal');
|
||||
|
||||
$this->assertEquals('stdGlobal', $element);
|
||||
}
|
||||
|
||||
public function testGetElementFromFile()
|
||||
{
|
||||
$locator = $this->newLocator();
|
||||
$locator->expects($this->once())
|
||||
->method('findMappingFile')
|
||||
->with($this->equalTo('stdClass'))
|
||||
->will($this->returnValue(__DIR__ . '/_files/stdClass.yml'));
|
||||
|
||||
$driver = new TestFileDriver($locator);
|
||||
|
||||
$this->assertEquals('stdClass', $driver->getElement('stdClass'));
|
||||
}
|
||||
|
||||
public function testGetAllClassNamesGlobalBasename()
|
||||
{
|
||||
$driver = new TestFileDriver($this->newLocator());
|
||||
$driver->setGlobalBasename("global");
|
||||
|
||||
$classNames = $driver->getAllClassNames();
|
||||
|
||||
$this->assertEquals(array('stdGlobal', 'stdGlobal2'), $classNames);
|
||||
}
|
||||
|
||||
public function testGetAllClassNamesFromMappingFile()
|
||||
{
|
||||
$locator = $this->newLocator();
|
||||
$locator->expects($this->any())
|
||||
->method('getAllClassNames')
|
||||
->with($this->equalTo(null))
|
||||
->will($this->returnValue(array('stdClass')));
|
||||
$driver = new TestFileDriver($locator);
|
||||
|
||||
$classNames = $driver->getAllClassNames();
|
||||
|
||||
$this->assertEquals(array('stdClass'), $classNames);
|
||||
}
|
||||
|
||||
public function testGetAllClassNamesBothSources()
|
||||
{
|
||||
$locator = $this->newLocator();
|
||||
$locator->expects($this->any())
|
||||
->method('getAllClassNames')
|
||||
->with($this->equalTo('global'))
|
||||
->will($this->returnValue(array('stdClass')));
|
||||
$driver = new TestFileDriver($locator);
|
||||
$driver->setGlobalBasename("global");
|
||||
|
||||
$classNames = $driver->getAllClassNames();
|
||||
|
||||
$this->assertEquals(array('stdGlobal', 'stdGlobal2', 'stdClass'), $classNames);
|
||||
}
|
||||
|
||||
public function testIsNotTransient()
|
||||
{
|
||||
$locator = $this->newLocator();
|
||||
$locator->expects($this->once())
|
||||
->method('fileExists')
|
||||
->with($this->equalTo('stdClass'))
|
||||
->will($this->returnValue( true ));
|
||||
|
||||
$driver = new TestFileDriver($locator);
|
||||
$driver->setGlobalBasename("global");
|
||||
|
||||
$this->assertFalse($driver->isTransient('stdClass'));
|
||||
$this->assertFalse($driver->isTransient('stdGlobal'));
|
||||
$this->assertFalse($driver->isTransient('stdGlobal2'));
|
||||
}
|
||||
|
||||
public function testIsTransient()
|
||||
{
|
||||
$locator = $this->newLocator();
|
||||
$locator->expects($this->once())
|
||||
->method('fileExists')
|
||||
->with($this->equalTo('stdClass2'))
|
||||
->will($this->returnValue( false ));
|
||||
|
||||
$driver = new TestFileDriver($locator);
|
||||
|
||||
$this->assertTrue($driver->isTransient('stdClass2'));
|
||||
}
|
||||
|
||||
public function testNonLocatorFallback()
|
||||
{
|
||||
$driver = new TestFileDriver(__DIR__ . '/_files', '.yml');
|
||||
$this->assertTrue($driver->isTransient('stdClass2'));
|
||||
$this->assertFalse($driver->isTransient('stdClass'));
|
||||
}
|
||||
|
||||
private function newLocator()
|
||||
{
|
||||
$locator = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\FileLocator');
|
||||
$locator->expects($this->any())->method('getFileExtension')->will($this->returnValue('.yml'));
|
||||
$locator->expects($this->any())->method('getPaths')->will($this->returnValue(array(__DIR__ . "/_files")));
|
||||
return $locator;
|
||||
}
|
||||
}
|
||||
|
||||
class TestFileDriver extends FileDriver
|
||||
{
|
||||
protected function loadMappingFile($file)
|
||||
{
|
||||
if (strpos($file, "global.yml") !== false) {
|
||||
return array('stdGlobal' => 'stdGlobal', 'stdGlobal2' => 'stdGlobal2');
|
||||
}
|
||||
return array('stdClass' => 'stdClass');
|
||||
}
|
||||
|
||||
public function loadMetadataForClass($className, ClassMetadata $metadata)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
18
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/PHPDriverTest.php
vendored
Normal file
18
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/PHPDriverTest.php
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Tests\DoctrineTestCase;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\PHPDriver;
|
||||
|
||||
class PHPDriverTest extends DoctrineTestCase
|
||||
{
|
||||
public function testLoadMetadata()
|
||||
{
|
||||
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
|
||||
$metadata->expects($this->once())->method('getFieldNames');
|
||||
|
||||
$driver = new PHPDriver(array(__DIR__ . "/_files"));
|
||||
$driver->loadMetadataForClass('TestEntity', $metadata);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\Common\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
|
||||
|
||||
/**
|
||||
* @group DCOM-93
|
||||
*/
|
||||
class RuntimeReflectionServiceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $reflectionService;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->reflectionService = new RuntimeReflectionService();
|
||||
}
|
||||
|
||||
public function testShortname()
|
||||
{
|
||||
$this->assertEquals("RuntimeReflectionServiceTest", $this->reflectionService->getClassShortName(__CLASS__));
|
||||
}
|
||||
|
||||
public function testClassNamespaceName()
|
||||
{
|
||||
$this->assertEquals("Doctrine\Tests\Common\Persistence\Mapping", $this->reflectionService->getClassNamespace(__CLASS__));
|
||||
}
|
||||
|
||||
public function testGetParentClasses()
|
||||
{
|
||||
$classes = $this->reflectionService->getParentClasses(__CLASS__);
|
||||
$this->assertTrue(count($classes) >= 1, "The test class ".__CLASS__." should have at least one parent.");
|
||||
}
|
||||
|
||||
public function testGetReflectionClass()
|
||||
{
|
||||
$class = $this->reflectionService->getClass(__CLASS__);
|
||||
$this->assertInstanceOf("ReflectionClass", $class);
|
||||
}
|
||||
|
||||
public function testGetMethods()
|
||||
{
|
||||
$this->assertTrue($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods"));
|
||||
$this->assertFalse($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods2"));
|
||||
}
|
||||
|
||||
public function testGetAccessibleProperty()
|
||||
{
|
||||
$reflProp = $this->reflectionService->getAccessibleProperty(__CLASS__, "reflectionService");
|
||||
$this->assertInstanceOf("ReflectionProperty", $reflProp);
|
||||
}
|
||||
}
|
||||
|
35
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/StaticPHPDriverTest.php
vendored
Normal file
35
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/StaticPHPDriverTest.php
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Tests\DoctrineTestCase;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver;
|
||||
|
||||
class StaticPHPDriverTest extends DoctrineTestCase
|
||||
{
|
||||
public function testLoadMetadata()
|
||||
{
|
||||
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
|
||||
$metadata->expects($this->once())->method('getFieldNames');
|
||||
|
||||
$driver = new StaticPHPDriver(array(__DIR__));
|
||||
$driver->loadMetadataForClass(__NAMESPACE__ . '\\TestEntity', $metadata);
|
||||
}
|
||||
|
||||
public function testGetAllClassNames()
|
||||
{
|
||||
$driver = new StaticPHPDriver(array(__DIR__));
|
||||
$classNames = $driver->getAllClassNames();
|
||||
|
||||
$this->assertContains(
|
||||
'Doctrine\Tests\Common\Persistence\Mapping\TestEntity', $classNames);
|
||||
}
|
||||
}
|
||||
|
||||
class TestEntity
|
||||
{
|
||||
static public function loadMetadata($metadata)
|
||||
{
|
||||
$metadata->getFieldNames();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\Common\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\StaticReflectionService;
|
||||
|
||||
/**
|
||||
* @group DCOM-93
|
||||
*/
|
||||
class StaticReflectionServiceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $reflectionService;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->reflectionService = new StaticReflectionService();
|
||||
}
|
||||
|
||||
public function testShortname()
|
||||
{
|
||||
$this->assertEquals("StaticReflectionServiceTest", $this->reflectionService->getClassShortName(__CLASS__));
|
||||
}
|
||||
|
||||
public function testClassNamespaceName()
|
||||
{
|
||||
$this->assertEquals("Doctrine\Tests\Common\Persistence\Mapping", $this->reflectionService->getClassNamespace(__CLASS__));
|
||||
}
|
||||
|
||||
public function testGetParentClasses()
|
||||
{
|
||||
$classes = $this->reflectionService->getParentClasses(__CLASS__);
|
||||
$this->assertTrue(count($classes) == 0, "The test class ".__CLASS__." should have no parents according to static reflection.");
|
||||
}
|
||||
|
||||
public function testGetReflectionClass()
|
||||
{
|
||||
$class = $this->reflectionService->getClass(__CLASS__);
|
||||
$this->assertNull($class);
|
||||
}
|
||||
|
||||
public function testGetMethods()
|
||||
{
|
||||
$this->assertTrue($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods"));
|
||||
$this->assertFalse($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods2"));
|
||||
}
|
||||
|
||||
public function testGetAccessibleProperty()
|
||||
{
|
||||
$reflProp = $this->reflectionService->getAccessibleProperty(__CLASS__, "reflectionService");
|
||||
$this->assertNull($reflProp);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Persistence\Mapping;
|
||||
|
||||
use Doctrine\Tests\DoctrineTestCase;
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator;
|
||||
|
||||
class SymfonyFileLocatorTest extends DoctrineTestCase
|
||||
{
|
||||
public function testGetPaths()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
$prefix = "Foo";
|
||||
|
||||
$locator = new SymfonyFileLocator(array($path => $prefix));
|
||||
$this->assertEquals(array($path), $locator->getPaths());
|
||||
|
||||
$locator = new SymfonyFileLocator(array($path => $prefix));
|
||||
$this->assertEquals(array($path), $locator->getPaths());
|
||||
}
|
||||
|
||||
public function testGetPrefixes()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
$prefix = "Foo";
|
||||
|
||||
$locator = new SymfonyFileLocator(array($path => $prefix));
|
||||
$this->assertEquals(array($path => $prefix), $locator->getNamespacePrefixes());
|
||||
}
|
||||
|
||||
public function testGetFileExtension()
|
||||
{
|
||||
$locator = new SymfonyFileLocator(array(), ".yml");
|
||||
$this->assertEquals(".yml", $locator->getFileExtension());
|
||||
$locator->setFileExtension(".xml");
|
||||
$this->assertEquals(".xml", $locator->getFileExtension());
|
||||
}
|
||||
|
||||
public function testFileExists()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
$prefix = "Foo";
|
||||
|
||||
$locator = new SymfonyFileLocator(array($path => $prefix), ".yml");
|
||||
|
||||
$this->assertTrue($locator->fileExists("Foo\stdClass"));
|
||||
$this->assertTrue($locator->fileExists("Foo\global"));
|
||||
$this->assertFalse($locator->fileExists("Foo\stdClass2"));
|
||||
$this->assertFalse($locator->fileExists("Foo\global2"));
|
||||
}
|
||||
|
||||
public function testGetAllClassNames()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
$prefix = "Foo";
|
||||
|
||||
$locator = new SymfonyFileLocator(array($path => $prefix), ".yml");
|
||||
$classes = $locator->getAllClassNames(null);
|
||||
sort($classes);
|
||||
|
||||
$this->assertEquals(array("Foo\\global", "Foo\\stdClass"), $classes);
|
||||
$this->assertEquals(array("Foo\\stdClass"), $locator->getAllClassNames("global"));
|
||||
}
|
||||
|
||||
public function testFindMappingFile()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
$prefix = "Foo";
|
||||
|
||||
$locator = new SymfonyFileLocator(array($path => $prefix), ".yml");
|
||||
|
||||
$this->assertEquals(__DIR__ . "/_files/stdClass.yml", $locator->findMappingFile("Foo\\stdClass"));
|
||||
}
|
||||
|
||||
public function testFindMappingFileNotFound()
|
||||
{
|
||||
$path = __DIR__ . "/_files";
|
||||
$prefix = "Foo";
|
||||
|
||||
$locator = new SymfonyFileLocator(array($path => $prefix), ".yml");
|
||||
|
||||
$this->setExpectedException(
|
||||
"Doctrine\Common\Persistence\Mapping\MappingException",
|
||||
"No mapping file found named '".__DIR__."/_files/stdClass2.yml' for class 'Foo\stdClass2'."
|
||||
);
|
||||
$locator->findMappingFile("Foo\\stdClass2");
|
||||
}
|
||||
}
|
3
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/_files/TestEntity.php
vendored
Normal file
3
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/_files/TestEntity.php
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
$metadata->getFieldNames();
|
1
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/_files/global.yml
vendored
Normal file
1
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/_files/global.yml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
test
|
1
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/_files/stdClass.yml
vendored
Normal file
1
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/_files/stdClass.yml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
test
|
247
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/PersistentObjectTest.php
vendored
Normal file
247
vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/PersistentObjectTest.php
vendored
Normal file
|
@ -0,0 +1,247 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Persistence;
|
||||
|
||||
use Doctrine\Common\Persistence\PersistentObject;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Common\Persistence\Mapping\ReflectionService;
|
||||
|
||||
/**
|
||||
* @group DDC-1448
|
||||
*/
|
||||
class PersistentObjectTest extends \Doctrine\Tests\DoctrineTestCase
|
||||
{
|
||||
private $cm;
|
||||
private $om;
|
||||
private $object;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->cm = new TestObjectMetadata;
|
||||
$this->om = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
|
||||
$this->om->expects($this->any())->method('getClassMetadata')
|
||||
->will($this->returnValue($this->cm));
|
||||
$this->object = new TestObject;
|
||||
PersistentObject::setObjectManager($this->om);
|
||||
$this->object->injectObjectManager($this->om, $this->cm);
|
||||
}
|
||||
|
||||
public function testGetObjectManager()
|
||||
{
|
||||
$this->assertSame($this->om, PersistentObject::getObjectManager());
|
||||
}
|
||||
|
||||
public function testNonMatchingObjectManager()
|
||||
{
|
||||
$this->setExpectedException('RuntimeException');
|
||||
$om = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
|
||||
$this->object->injectObjectManager($om, $this->cm);
|
||||
}
|
||||
|
||||
public function testGetField()
|
||||
{
|
||||
$this->assertEquals('beberlei', $this->object->getName());
|
||||
}
|
||||
|
||||
public function testSetField()
|
||||
{
|
||||
$this->object->setName("test");
|
||||
$this->assertEquals("test", $this->object->getName());
|
||||
}
|
||||
|
||||
public function testGetIdentifier()
|
||||
{
|
||||
$this->assertEquals(1, $this->object->getId());
|
||||
}
|
||||
|
||||
public function testSetIdentifier()
|
||||
{
|
||||
$this->setExpectedException('BadMethodCallException');
|
||||
$this->object->setId(2);
|
||||
}
|
||||
|
||||
public function testSetUnknownField()
|
||||
{
|
||||
$this->setExpectedException('BadMethodCallException');
|
||||
$this->object->setUnknown("test");
|
||||
}
|
||||
|
||||
public function testGetUnknownField()
|
||||
{
|
||||
$this->setExpectedException('BadMethodCallException');
|
||||
$this->object->getUnknown();
|
||||
}
|
||||
|
||||
public function testGetToOneAssociation()
|
||||
{
|
||||
$this->assertNull($this->object->getParent());
|
||||
}
|
||||
|
||||
public function testSetToOneAssociation()
|
||||
{
|
||||
$parent = new TestObject();
|
||||
$this->object->setParent($parent);
|
||||
$this->assertSame($parent, $this->object->getParent($parent));
|
||||
}
|
||||
|
||||
public function testSetInvalidToOneAssocation()
|
||||
{
|
||||
$parent = new \stdClass();
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$this->object->setParent($parent);
|
||||
}
|
||||
|
||||
public function testSetToOneAssociationNull()
|
||||
{
|
||||
$parent = new TestObject();
|
||||
$this->object->setParent($parent);
|
||||
$this->object->setParent(null);
|
||||
$this->assertNull($this->object->getParent());
|
||||
}
|
||||
|
||||
public function testAddToManyAssocation()
|
||||
{
|
||||
$child = new TestObject();
|
||||
$this->object->addChildren($child);
|
||||
|
||||
$this->assertSame($this->object, $child->getParent());
|
||||
$this->assertEquals(1, count($this->object->getChildren()));
|
||||
|
||||
$child = new TestObject();
|
||||
$this->object->addChildren($child);
|
||||
|
||||
$this->assertEquals(2, count($this->object->getChildren()));
|
||||
}
|
||||
|
||||
public function testAddInvalidToManyAssocation()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$this->object->addChildren(new \stdClass());
|
||||
}
|
||||
|
||||
public function testNoObjectManagerSet()
|
||||
{
|
||||
PersistentObject::setObjectManager(null);
|
||||
$child = new TestObject();
|
||||
|
||||
$this->setExpectedException('RuntimeException');
|
||||
$child->setName("test");
|
||||
}
|
||||
|
||||
public function testInvalidMethod()
|
||||
{
|
||||
$this->setExpectedException('BadMethodCallException');
|
||||
$this->object->asdf();
|
||||
}
|
||||
|
||||
public function testAddInvalidCollection()
|
||||
{
|
||||
$this->setExpectedException('BadMethodCallException');
|
||||
$this->object->addAsdf(new \stdClass());
|
||||
}
|
||||
}
|
||||
|
||||
class TestObject extends PersistentObject
|
||||
{
|
||||
protected $id = 1;
|
||||
protected $name = 'beberlei';
|
||||
protected $parent;
|
||||
protected $children;
|
||||
}
|
||||
|
||||
class TestObjectMetadata implements ClassMetadata
|
||||
{
|
||||
|
||||
public function getAssociationMappedByTargetField($assocName)
|
||||
{
|
||||
$assoc = array('children' => 'parent');
|
||||
return $assoc[$assocName];
|
||||
}
|
||||
|
||||
public function getAssociationNames()
|
||||
{
|
||||
return array('parent', 'children');
|
||||
}
|
||||
|
||||
public function getAssociationTargetClass($assocName)
|
||||
{
|
||||
return __NAMESPACE__ . '\TestObject';
|
||||
}
|
||||
|
||||
public function getFieldNames()
|
||||
{
|
||||
return array('id', 'name');
|
||||
}
|
||||
|
||||
public function getIdentifier()
|
||||
{
|
||||
return array('id');
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return __NAMESPACE__ . '\TestObject';
|
||||
}
|
||||
|
||||
public function getReflectionClass()
|
||||
{
|
||||
return new \ReflectionClass($this->getName());
|
||||
}
|
||||
|
||||
public function getTypeOfField($fieldName)
|
||||
{
|
||||
$types = array('id' => 'integer', 'name' => 'string');
|
||||
return $types[$fieldName];
|
||||
}
|
||||
|
||||
public function hasAssociation($fieldName)
|
||||
{
|
||||
return in_array($fieldName, array('parent', 'children'));
|
||||
}
|
||||
|
||||
public function hasField($fieldName)
|
||||
{
|
||||
return in_array($fieldName, array('id', 'name'));
|
||||
}
|
||||
|
||||
public function isAssociationInverseSide($assocName)
|
||||
{
|
||||
return ($assocName === 'children');
|
||||
}
|
||||
|
||||
public function isCollectionValuedAssociation($fieldName)
|
||||
{
|
||||
return ($fieldName === 'children');
|
||||
}
|
||||
|
||||
public function isIdentifier($fieldName)
|
||||
{
|
||||
return $fieldName === 'id';
|
||||
}
|
||||
|
||||
public function isSingleValuedAssociation($fieldName)
|
||||
{
|
||||
return $fieldName === 'parent';
|
||||
}
|
||||
|
||||
public function getIdentifierValues($entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getIdentifierFieldNames()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function initializeReflection(ReflectionService $reflService)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function wakeupReflection(ReflectionService $reflService)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue