Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to get configured metadata classes.
- Loading branch information
jstout24
committed
Dec 17, 2012
1 parent
a965c62
commit 9c74000
Showing
11 changed files
with
339 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
<?php | |||
|
|||
/* | |||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com> | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
namespace Metadata; | |||
|
|||
/** | |||
* Interface for advanced Metadata Factory implementations. | |||
* | |||
* @author Johannes M. Schmitt <schmittjoh@gmail.com> | |||
* @author Jordan Stout <j@jrdn.org> | |||
*/ | |||
interface AdvancedMetadataFactoryInterface extends MetadataFactoryInterface | |||
{ | |||
/** | |||
* Gets all the possible classes. | |||
* | |||
* @throws \RuntimeException if driver does not an advanced driver. | |||
* @return array | |||
*/ | |||
public function getAllClassNames(); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
<?php | |||
|
|||
/* | |||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com> | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
namespace Metadata\Driver; | |||
|
|||
/** | |||
* Forces advanced logic to drivers. | |||
* | |||
* @author Jordan Stout <j@jrdn.org> | |||
*/ | |||
interface AdvancedDriverInterface extends DriverInterface | |||
{ | |||
/** | |||
* Gets all the metadata class names known to this driver. | |||
* | |||
* @return array | |||
*/ | |||
public function getAllClassNames(); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
<?php | |||
|
|||
/* | |||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com> | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
namespace Metadata\Driver; | |||
|
|||
/** | |||
* Forces advanced logic on a file locator. | |||
* | |||
* @author Jordan Stout <j@jrdn.org> | |||
*/ | |||
interface AdvancedFileLocatorInterface extends FileLocatorInterface | |||
{ | |||
/** | |||
* Finds all possible metadata files. | |||
* | |||
* @param string $extension | |||
* | |||
* @return array | |||
*/ | |||
public function findAllClasses($extension); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,85 @@ | |||
<?php | |||
|
|||
namespace Metadata\Tests\Driver; | |||
|
|||
use Metadata\ClassMetadata; | |||
|
|||
/** | |||
* @author Jordan Stout <j@jrdn.org> | |||
*/ | |||
class AbstractFileDriverTest extends \PHPUnit_Framework_TestCase | |||
{ | |||
private static $extension = 'jms_metadata.yml'; | |||
|
|||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | |||
private $locator; | |||
|
|||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | |||
private $driver; | |||
|
|||
public function setUp() | |||
{ | |||
$this->locator = $this->getMock('Metadata\Driver\FileLocator', array(), array(), '', false); | |||
$this->driver = $this->getMockBuilder('Metadata\Driver\AbstractFileDriver') | |||
->setConstructorArgs(array($this->locator)) | |||
->getMockForAbstractClass(); | |||
|
|||
$this->driver->expects($this->any())->method('getExtension')->will($this->returnValue(self::$extension)); | |||
} | |||
|
|||
public function testLoadMetadataForClass() | |||
{ | |||
$class = new \ReflectionClass('\stdClass'); | |||
$this->locator | |||
->expects($this->once()) | |||
->method('findFileForClass') | |||
->with($class, self::$extension) | |||
->will($this->returnValue('Some\Path')); | |||
|
|||
$this->driver | |||
->expects($this->once()) | |||
->method('loadMetadataFromFile') | |||
->with($class, 'Some\Path') | |||
->will($this->returnValue($metadata = new ClassMetadata('\stdClass'))); | |||
|
|||
$this->assertSame($metadata, $this->driver->loadMetadataForClass($class)); | |||
} | |||
|
|||
public function testLoadMetadataForClassWillReturnNull() | |||
{ | |||
$class = new \ReflectionClass('\stdClass'); | |||
$this->locator | |||
->expects($this->once()) | |||
->method('findFileForClass') | |||
->with($class, self::$extension) | |||
->will($this->returnValue(null)); | |||
|
|||
$this->assertSame(null, $this->driver->loadMetadataForClass($class)); | |||
} | |||
|
|||
public function testGetAllClassNames() | |||
{ | |||
$class = new \ReflectionClass('\stdClass'); | |||
$this->locator | |||
->expects($this->once()) | |||
->method('findAllClasses') | |||
->with(self::$extension) | |||
->will($this->returnValue(array('\stdClass'))); | |||
|
|||
$this->assertSame(array('\stdClass'), $this->driver->getAllClassNames($class)); | |||
} | |||
|
|||
public function testGetAllClassNamesThrowsRuntimeException() | |||
{ | |||
$this->setExpectedException('RuntimeException'); | |||
|
|||
$locator = $this->getMock('Metadata\Driver\FileLocatorInterface', array(), array(), '', false); | |||
$driver = $this->getMockBuilder('Metadata\Driver\AbstractFileDriver') | |||
->setConstructorArgs(array($locator)) | |||
->getMockForAbstractClass(); | |||
$class = new \ReflectionClass('\stdClass'); | |||
$locator->expects($this->never())->method('findAllClasses'); | |||
|
|||
$driver->getAllClassNames($class); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.