Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -0,0 +1,97 @@
<?php
namespace Doctrine\Tests\Common\Persistence;
use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\Tests\Common\Persistence\Mapping\TestClassMetadataFactory;
use Doctrine\Tests\DoctrineTestCase;
use PHPUnit_Framework_TestCase;
/**
* @groups DCOM-270
* @uses Doctrine\Tests\Common\Persistence\TestObject
*/
class ManagerRegistryTest extends DoctrineTestCase
{
/**
* @var TestManagerRegistry
*/
private $mr;
/**
* {@inheritdoc}
*/
public function setUp()
{
$this->mr = new TestManagerRegistry(
'ORM',
array('default_connection'),
array('default_manager'),
'default',
'default',
'Doctrine\Common\Persistence\ObjectManagerAware'
);
}
public function testGetManagerForClass()
{
$this->mr->getManagerForClass('Doctrine\Tests\Common\Persistence\TestObject');
}
public function testGetManagerForInvalidClass()
{
$this->setExpectedException(
'ReflectionException',
'Class Doctrine\Tests\Common\Persistence\TestObjectInexistent does not exist'
);
$this->mr->getManagerForClass('prefix:TestObjectInexistent');
}
public function testGetManagerForAliasedClass()
{
$this->mr->getManagerForClass('prefix:TestObject');
}
public function testGetManagerForInvalidAliasedClass()
{
$this->setExpectedException(
'ReflectionException',
'Class Doctrine\Tests\Common\Persistence\TestObject:Foo does not exist'
);
$this->mr->getManagerForClass('prefix:TestObject:Foo');
}
}
class TestManager extends PHPUnit_Framework_TestCase
{
public function getMetadataFactory()
{
$driver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
return new TestClassMetadataFactory($driver, $metadata);
}
}
class TestManagerRegistry extends AbstractManagerRegistry
{
protected function getService($name)
{
return new TestManager();
}
/**
* {@inheritdoc}
*/
protected function resetService($name)
{
}
public function getAliasNamespace($alias)
{
return __NAMESPACE__;
}
}

View file

@ -0,0 +1,29 @@
<?php
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
class AnnotationDriverTest extends \PHPUnit_Framework_TestCase
{
public function testGetAllClassNames()
{
$reader = new AnnotationReader();
$driver = new SimpleAnnotationDriver($reader, array(__DIR__ . '/_files/annotation'));
$classes = $driver->getAllClassNames();
$this->assertEquals(array('Doctrine\TestClass'), $classes);
}
}
class SimpleAnnotationDriver extends AnnotationDriver
{
protected $entityAnnotationClasses = array('Doctrine\Entity' => true);
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
}
}

View file

@ -0,0 +1,152 @@
<?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\Persistence\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');
$defaultDriver = $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));
$defaultDriver->expects($this->never())
->method('loadMetadataForClass');
$defaultDriver->expects($this->once())
->method('isTransient')
->with($this->equalTo($entityClassName))
->will($this->returnValue(true));
$this->assertNull($chain->getDefaultDriver());
$chain->setDefaultDriver($defaultDriver);
$chain->addDriver($companyDriver, 'Doctrine\Tests\Models\Company');
$this->assertSame($defaultDriver, $chain->getDefaultDriver());
$this->assertTrue($chain->isTransient($entityClassName));
$this->assertFalse($chain->isTransient($managerClassName));
}
public function testDefaultDriverGetAllClassNames()
{
$companyDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$defaultDriver = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver');
$chain = new MappingDriverChain();
$companyDriver->expects($this->once())
->method('getAllClassNames')
->will($this->returnValue(array('Doctrine\Tests\Models\Company\Foo')));
$defaultDriver->expects($this->once())
->method('getAllClassNames')
->will($this->returnValue(array('Other\Class')));
$chain->setDefaultDriver($defaultDriver);
$chain->addDriver($companyDriver, 'Doctrine\Tests\Models\Company');
$classNames = $chain->getAllClassNames();
$this->assertEquals(array('Doctrine\Tests\Models\Company\Foo', 'Other\Class'), $classNames);
}
}
class DriverChainEntity
{
}

View file

@ -0,0 +1,209 @@
<?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 testGetMetadataForAbsentClass()
{
$this->setExpectedException('Doctrine\Common\Persistence\Mapping\MappingException');
$this->cmf->getMetadataFor(__NAMESPACE__ . '\AbsentClass');
}
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()
{
$this->cmf->getMetadataFor('prefix:ChildEntity');
$this->assertTrue($this->cmf->hasMetadataFor(__NAMESPACE__ . '\ChildEntity'));
$this->assertTrue($this->cmf->hasMetadataFor('prefix:ChildEntity'));
}
/**
* @group DCOM-270
*/
public function testGetInvalidAliasedMetadata()
{
$this->setExpectedException(
'Doctrine\Common\Persistence\Mapping\MappingException',
'Class \'Doctrine\Tests\Common\Persistence\Mapping\ChildEntity:Foo\' does not exist'
);
$this->cmf->getMetadataFor('prefix:ChildEntity:Foo');
}
/**
* @group DCOM-270
*/
public function testClassIsTransient()
{
$this->assertTrue($this->cmf->isTransient('prefix:ChildEntity:Foo'));
}
public function testWillFallbackOnNotLoadedMetadata()
{
$classMetadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$this->cmf->fallbackCallback = function () use ($classMetadata) {
return $classMetadata;
};
$this->cmf->metadata = null;
$this->assertSame($classMetadata, $this->cmf->getMetadataFor('Foo'));
}
public function testWillFailOnFallbackFailureWithNotLoadedMetadata()
{
$this->cmf->fallbackCallback = function () {
return null;
};
$this->cmf->metadata = null;
$this->setExpectedException('Doctrine\Common\Persistence\Mapping\MappingException');
$this->cmf->getMetadataFor('Foo');
}
}
class TestClassMetadataFactory extends AbstractClassMetadataFactory
{
public $driver;
public $metadata;
/** @var callable|null */
public $fallbackCallback;
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;
}
protected function onNotFoundMetadata($className)
{
if (! $fallback = $this->fallbackCallback) {
return null;
}
return $fallback();
}
public function isTransient($class)
{
return true;
}
}
class RootEntity
{
}
class ChildEntity extends RootEntity
{
}

View file

@ -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"));
}
}

View 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)
{
}
}

View 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);
}
}

View file

@ -0,0 +1,84 @@
<?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 MIT license. 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
{
/**
* @var RuntimeReflectionService
*/
private $reflectionService;
public $unusedPublicProperty;
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 testGetParentClassesForAbsentClass()
{
$this->setExpectedException('Doctrine\Common\Persistence\Mapping\MappingException');
$this->reflectionService->getParentClasses(__NAMESPACE__ . '\AbsentClass');
}
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);
$reflProp = $this->reflectionService->getAccessibleProperty(__CLASS__, "unusedPublicProperty");
$this->assertInstanceOf("Doctrine\Common\Reflection\RuntimePublicReflectionProperty", $reflProp);
}
}

View 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();
}
}

View file

@ -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 MIT license. 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->assertTrue($this->reflectionService->hasPublicMethod(__CLASS__, "testGetMethods2"));
}
public function testGetAccessibleProperty()
{
$reflProp = $this->reflectionService->getAccessibleProperty(__CLASS__, "reflectionService");
$this->assertNull($reflProp);
}
}

View file

@ -0,0 +1,173 @@
<?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"));
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Namespace separator should not be empty
*/
public function testInvalidCustomNamespaceSeparator()
{
$path = __DIR__ . "/_files";
$prefix = "Foo";
new SymfonyFileLocator(array($path => $prefix), ".yml", null);
}
public function customNamespaceSeparatorProvider()
{
return array(
'directory separator' => array(DIRECTORY_SEPARATOR, "/_custom_ns/dir"),
'default dot separator' => array('.', "/_custom_ns/dot"),
);
}
/**
* @dataProvider customNamespaceSeparatorProvider
*
* @param $separator string Directory separator to test against
* @param $dir string Path to load mapping data from
*
* @throws \Doctrine\Common\Persistence\Mapping\MappingException
*/
public function testGetClassNamesWithCustomNsSeparator($separator, $dir)
{
$path = __DIR__ . $dir;
$prefix = "Foo";
$locator = new SymfonyFileLocator(array($path => $prefix), ".yml", $separator);
$classes = $locator->getAllClassNames(null);
sort($classes);
$this->assertEquals(array("Foo\\stdClass", "Foo\\sub\\subClass", "Foo\\sub\\subsub\\subSubClass"), $classes);
}
public function customNamespaceLookupQueryProvider()
{
return array(
'directory separator' => array(
DIRECTORY_SEPARATOR,
"/_custom_ns/dir",
array(
"stdClass.yml" => "Foo\\stdClass",
"sub/subClass.yml" => "Foo\\sub\\subClass",
"sub/subsub/subSubClass.yml" => "Foo\\sub\\subsub\\subSubClass",
)
),
'default dot separator' => array(
'.',
"/_custom_ns/dot",
array(
"stdClass.yml" => "Foo\\stdClass",
"sub.subClass.yml" => "Foo\\sub\\subClass",
"sub.subsub.subSubClass.yml" => "Foo\\sub\\subsub\\subSubClass",
)
),
);
}
/** @dataProvider customNamespaceLookupQueryProvider
* @param $separator string Directory separator to test against
* @param $dir string Path to load mapping data from
* @param $files array Files to lookup classnames
*
* @throws \Doctrine\Common\Persistence\Mapping\MappingException
*/
public function testFindMappingFileWithCustomNsSeparator($separator, $dir, $files)
{
$path = __DIR__ . $dir;
$prefix = "Foo";
$locator = new SymfonyFileLocator(array($path => $prefix), ".yml", $separator);
foreach ($files as $filePath => $className) {
$this->assertEquals(realpath($path .'/'. $filePath), realpath($locator->findMappingFile($className)));
}
}
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");
}
}

View file

@ -0,0 +1,3 @@
<?php
$metadata->getFieldNames();

View file

@ -0,0 +1,17 @@
<?php
namespace Doctrine;
/**
* @Doctrine\Entity
*/
class TestClass
{
}
/**
* @Annotation
*/
class Entity
{
}

View file

@ -0,0 +1,60 @@
<?php
namespace Doctrine\Tests\Common\Persistence;
use Doctrine\Common\Persistence\ObjectManagerDecorator;
use Doctrine\Common\Persistence\ObjectManager;
class NullObjectManagerDecorator extends ObjectManagerDecorator
{
public function __construct(ObjectManager $wrapped)
{
$this->wrapped = $wrapped;
}
}
class ObjectManagerDecoratorTest extends \PHPUnit_Framework_TestCase
{
private $wrapped;
private $decorated;
public function setUp()
{
$this->wrapped = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
$this->decorated = new NullObjectManagerDecorator($this->wrapped);
}
public function getMethodParameters()
{
$class = new \ReflectionClass('Doctrine\Common\Persistence\ObjectManager');
$methods = array();
foreach ($class->getMethods() as $method) {
if ($method->getNumberOfRequiredParameters() === 0) {
$methods[] = array($method->getName(), array());
} elseif ($method->getNumberOfRequiredParameters() > 0) {
$methods[] = array($method->getName(), array_fill(0, $method->getNumberOfRequiredParameters(), 'req') ?: array());
}
if ($method->getNumberOfParameters() != $method->getNumberOfRequiredParameters()) {
$methods[] = array($method->getName(), array_fill(0, $method->getNumberOfParameters(), 'all') ?: array());
}
}
return $methods;
}
/**
* @dataProvider getMethodParameters
*/
public function testAllMethodCallsAreDelegatedToTheWrappedInstance($method, array $parameters)
{
$stub = $this->wrapped
->expects($this->once())
->method($method)
->will($this->returnValue('INNER VALUE FROM ' . $method));
call_user_func_array(array($stub, 'with'), $parameters);
$this->assertSame('INNER VALUE FROM ' . $method, call_user_func_array(array($this->decorated, $method), $parameters));
}
}

View 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 testSetInvalidToOneAssociation()
{
$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 testAddToManyAssociation()
{
$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 testAddInvalidToManyAssociation()
{
$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)
{
}
}