Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Better unit test asset namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Nov 17, 2014
1 parent e1d4f22 commit 0ef0114
Show file tree
Hide file tree
Showing 30 changed files with 65 additions and 93 deletions.
2 changes: 1 addition & 1 deletion test/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @copyright Copyright (c) 2014 Zend Technologies USA Inc. (http://www.zend.com)
*/

namespace ZFTest\Apigility\Admin;
namespace ZFTest\Apigility;

use Zend\Loader\AutoloaderFactory;
use RuntimeException;
Expand Down
29 changes: 0 additions & 29 deletions test/assets/documentation/ZFTest.ormdesigner2

This file was deleted.

2 changes: 1 addition & 1 deletion test/assets/module/DbApiOriginal/Module.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
require __DIR__ . '/src/DbApi/Module.php';
require __DIR__ . '/src/ZFTestApigilityDbApi/Module.php';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace DbApi;
namespace ZFTestApigilityDbApi;

use ZF\Apigility\Provider\ApigilityProviderInterface;

Expand Down
2 changes: 1 addition & 1 deletion test/assets/module/DbMongoApiOriginal/Module.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
require __DIR__ . '/src/DbMongoApi/Module.php';
require __DIR__ . '/src/ZFTestApigilityDbMongoApi/Module.php';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Db;
namespace ZFTestApigilityDbMongoApi;

use ZF\Apigility\Provider\ApigilityProviderInterface;

Expand Down
2 changes: 1 addition & 1 deletion test/assets/module/DbMongoOriginal/Module.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
require __DIR__ . '/src/DbMongo/Module.php';
require __DIR__ . '/src/ZFTestApigilityDbMongo/Module.php';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DbMongo;
namespace ZFTestApigilityDbMongo;

return [
'doctrine' => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DbMongo\Document\Meta:
ZFTestApigilityDbMongo\Document\Meta:
db: zf_apigility_doctrine_server_test
collection: meta
repositoryClass: DbMongo\Repository\MetaRepository
repositoryClass: ZFTestApigilityDbMongo\Repository\MetaRepository
fields:
id:
id: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DbMongo\Document;
namespace ZFTestApigilityDbMongo\Document;

class Meta
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace DbMongoApi;
namespace ZFTestApigilityDbMongo;

use ZF\Apigility\Provider\ApigilityProviderInterface;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DbMongo\Repository;
namespace ZFTestApigilityDbMongo\Repository;

use Doctrine\ODM\MongoDB\DocumentRepository;

Expand Down
2 changes: 1 addition & 1 deletion test/assets/module/DbOriginal/Module.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
require __DIR__ . '/src/Db/Module.php';
require __DIR__ . '/src/ZFTestApigilityDb/Module.php';
2 changes: 1 addition & 1 deletion test/assets/module/DbOriginal/config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Db;
namespace ZFTestApigilityDb;

return [
'doctrine' => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Db\Entity\Album">
<entity name="ZFTestApigilityDb\Entity\Album">
<id name="id" type="integer">
<generator strategy="AUTO"/>
</id>
<field name="name" type="string" nullable="true"/>
<field name="createdAt" type="datetime" nullable="true"/>
<many-to-one field="artist" target-entity="Db\Entity\Artist" inversed-by="album">
<many-to-one field="artist" target-entity="ZFTestApigilityDb\Entity\Artist" inversed-by="album">
<join-columns>
<join-column name="artist_id" referenced-column-name="id"/>
</join-columns>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Db\Entity\Artist">
<entity name="ZFTestApigilityDb\Entity\Artist">
<id name="id" type="integer">
<generator strategy="AUTO"/>
</id>
<field name="name" type="string" nullable="true"/>
<field name="createdAt" type="datetime" nullable="true"/>
<one-to-many field="album" target-entity="Db\Entity\Album" mapped-by="artist"/>
<one-to-many field="album" target-entity="ZFTestApigilityDb\Entity\Album" mapped-by="artist"/>
</entity>
</doctrine-mapping>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Db\Entity;
namespace ZFTestApigilityDb\Entity;

class Album
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Db\Entity;
namespace ZFTestApigilityDb\Entity;

use \Doctrine\Common\Collections\ArrayCollection;

Expand Down Expand Up @@ -64,11 +64,11 @@ public function getAlbum()
*/
public function addAlbum($album)
{
if ($album instanceof \Db\Entity\Album) {
if ($album instanceof \ZFTestApigilityDb\Entity\Album) {
$this->album[] = $album;
} elseif ($album instanceof ArrayCollection) {
foreach ($album as $a) {
if ( ! $a instanceof \Db\Entity\Album) {
if ( ! $a instanceof \ZFTestApigilityDb\Entity\Album) {
throw new \Exception('Invalid type in addAlbum');
}
$this->album->add($a);
Expand All @@ -85,11 +85,11 @@ public function addAlbum($album)
*/
public function removeAlbum($album)
{
if ($album instanceof \Db\Entity\Album) {
if ($album instanceof \ZFTestApigilityDb\Entity\Album) {
$this->album[] = $album;
} elseif ($album instanceof ArrayCollection) {
foreach ($album as $a) {
if ( ! $a instanceof \Db\Entity\Album) {
if ( ! $a instanceof \ZFTestApigilityDb\Entity\Album) {
throw new \Exception('Invalid type remove addAlbum');
}
$this->album->removeElement($a);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace DbMongo;

namespace ZFTestApigilityDb;

use ZF\Apigility\Provider\ApigilityProviderInterface;

Expand Down
2 changes: 1 addition & 1 deletion test/assets/module/GeneralOriginal/Module.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
require __DIR__ . '/src/General/Module.php';
require __DIR__ . '/src/ZFTestApigilityGeneral/Module.php';
4 changes: 2 additions & 2 deletions test/assets/module/GeneralOriginal/config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Db;
namespace ZFTestApigilityGeneral;

return [
'service_manager' => [
'invokables' => [
'General\Listener\EventCatcher' => 'General\Listener\EventCatcher',
'ZFTestApigilityGeneral\Listener\EventCatcher' => 'ZFTestApigilityGeneral\Listener\EventCatcher',
]
]
];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace General\Listener;
namespace ZFTestApigilityGeneral\Listener;

use Zend\EventManager\Event;
use Zend\EventManager\SharedEventManagerInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace General;
namespace ZFTestApigilityGeneral;

use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
Expand Down Expand Up @@ -37,7 +37,7 @@ public function onBootstrap(EventInterface $e)
$eventManager = $application->getEventManager();
$sharedEventManager = $eventManager->getSharedManager();

$eventCatcher = $serviceManager->get('General\Listener\EventCatcher');
$eventCatcher = $serviceManager->get('ZFTestApigilityGeneral\Listener\EventCatcher');
$sharedEventManager->attachAggregate($eventCatcher);
}

Expand Down
12 changes: 6 additions & 6 deletions test/config/ODM/application.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
'ZF\ApiProblem',
'ZF\Apigility\Doctrine\Admin',
'ZF\Apigility\Doctrine\Server',
'General',
'DbMongo',
'DbMongoApi',
'ZFTestApigilityGeneral',
'ZFTestApigilityDbMongo',
'ZFTestApigilityDbMongoApi',
),
'module_listener_options' => array(
'config_glob_paths' => array(
__DIR__ . '/local.php',
),
'module_paths' => array(
'General' => __DIR__ . '/../../assets/module/General',
'DbMongo' => __DIR__ . '/../../assets/module/DbMongo',
'DbMongoApi' => __DIR__ . '/../../assets/module/DbMongoApi',
'ZFTestApigilityGeneral' => __DIR__ . '/../../assets/module/General',
'ZFTestApigilityDbMongo' => __DIR__ . '/../../assets/module/DbMongo',
'ZFTestApigilityDbMongoApi' => __DIR__ . '/../../assets/module/DbMongoApi',
),
),
);
12 changes: 6 additions & 6 deletions test/config/ORM/application.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
'ZF\ApiProblem',
'ZF\Apigility\Doctrine\Admin',
'ZF\Apigility\Doctrine\Server',
'General',
'Db',
'DbApi',
'ZFTestApigilityGeneral',
'ZFTestApigilityDb',
'ZFTestApigilityDbApi',
),
'module_listener_options' => array(
'config_glob_paths' => array(
__DIR__ . '/local.php',
),
'module_paths' => array(
'General' => __DIR__ . '/../../assets/module/General',
'Db' => __DIR__ . '/../../assets/module/Db',
'DbApi' => __DIR__ . '/../../assets/module/DbApi',
'ZFTestApigilityGeneral' => __DIR__ . '/../../assets/module/General',
'ZFTestApigilityDb' => __DIR__ . '/../../assets/module/Db',
'ZFTestApigilityDbApi' => __DIR__ . '/../../assets/module/DbApi',
),
),
);
12 changes: 6 additions & 6 deletions test/config/application.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
'ZF\ApiProblem',
'ZF\Apigility\Doctrine\Admin',
'ZF\Apigility\Doctrine\Server',
'General',
'Db',
'DbApi',
'ZFTestApigilityGeneral',
'ZFTestApigilityDb',
'ZFTestApigilityDbApi',
),
'module_listener_options' => array(
'config_glob_paths' => array(
__DIR__ . '/testing.config.php',
),
'module_paths' => array(
'General' => __DIR__ . '/../../assets/module/General',
'Db' => __DIR__ . '/../assets/module/Db',
'DbApi' => __DIR__ . '/../assets/module/DbApi',
'ZFTestApigilityGeneral' => __DIR__ . '/../../assets/module/General',
'ZFTestApigilityDb' => __DIR__ . '/../assets/module/Db',
'ZFTestApigilityDbApi' => __DIR__ . '/../assets/module/DbApi',
),
),
);
6 changes: 3 additions & 3 deletions test/src/Server/ODM/CRUD/CRUDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace ZFTest\Apigility\Doctrine\Server\ODM\CRUD;

use General\Listener\EventCatcher;
use ZFTestApigilityGeneral\Listener\EventCatcher;
use Zend\Http\Request;
use DbMongo\Document\Meta as MetaEntity;
use ZFTestApigilityDbMongo\Document\Meta as MetaEntity;
use ZF\Apigility\Doctrine\Server\Event\DoctrineResourceEvent;

class CRUDTest extends \Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase
Expand Down Expand Up @@ -37,7 +37,7 @@ protected function clearData()
protected function validateTriggeredEvents($expectedEvents)
{
$serviceManager = $this->getApplication()->getServiceManager();
$eventCatcher = $serviceManager->get('General\Listener\EventCatcher');
$eventCatcher = $serviceManager->get('ZFTestApigilityGeneral\Listener\EventCatcher');

$this->assertEquals($expectedEvents, $eventCatcher->getCaughtEvents());
}
Expand Down
4 changes: 2 additions & 2 deletions test/src/Server/ODM/Setup/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public function testBuildOdmApi()
$metaResourceDefinition = [
"objectManager"=> "doctrine.documentmanager.odm_default",
"serviceName" => "Meta",
"entityClass" => "DbMongo\\Document\\Meta",
"entityClass" => "ZFTestApigilityDbMongo\\Document\\Meta",
"routeIdentifierName" => "meta_id",
"entityIdentifierName" => "id",
"routeMatch" => "/test/meta",
];

$resource->setModuleName('DbMongoApi');
$resource->setModuleName('ZFTestApigilityDbMongoApi');
$metaEntity = $resource->create($metaResourceDefinition);

$this->assertInstanceOf('ZF\Apigility\Doctrine\Admin\Model\DoctrineRestServiceEntity', $metaEntity);
Expand Down
10 changes: 5 additions & 5 deletions test/src/Server/ORM/CRUD/CRUDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use Doctrine\ORM\Tools\SchemaTool;
use Zend\Http\Request;
use Db\Entity\Artist as ArtistEntity;
use ZFTestApigilityDb\Entity\Artist as ArtistEntity;
use ZF\Apigility\Doctrine\Server\Event\DoctrineResourceEvent;

class CRUDTest extends \Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase
Expand All @@ -33,7 +33,7 @@ public function setUp()
protected function validateTriggeredEvents($expectedEvents)
{
$serviceManager = $this->getApplication()->getServiceManager();
$eventCatcher = $serviceManager->get('General\Listener\EventCatcher');
$eventCatcher = $serviceManager->get('ZFTestApigilityGeneral\Listener\EventCatcher');

$this->assertEquals($expectedEvents, $eventCatcher->getCaughtEvents());
}
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testPatch()
$body = json_decode($this->getResponse()->getBody(), true);
$this->assertEquals('ArtistOnePatchEdit', $body['name']);

$foundEntity = $em->getRepository('Db\Entity\Artist')->find($artist->getId());
$foundEntity = $em->getRepository('ZFTestApigilityDb\Entity\Artist')->find($artist->getId());
$this->assertEquals('ArtistOnePatchEdit', $foundEntity->getName());
$this->validateTriggeredEvents([DoctrineResourceEvent::EVENT_PATCH_PRE, DoctrineResourceEvent::EVENT_PATCH_POST]);
}
Expand All @@ -150,7 +150,7 @@ public function testPut()
$body = json_decode($this->getResponse()->getBody(), true);
$this->assertEquals('ArtistSevenPutEdit', $body['name']);

$foundEntity = $em->getRepository('Db\Entity\Artist')->find($artist->getId());
$foundEntity = $em->getRepository('ZFTestApigilityDb\Entity\Artist')->find($artist->getId());
$this->assertEquals('ArtistSevenPutEdit', $foundEntity->getName());
$this->validateTriggeredEvents([DoctrineResourceEvent::EVENT_UPDATE_PRE, DoctrineResourceEvent::EVENT_UPDATE_POST]);
}
Expand All @@ -175,7 +175,7 @@ public function testDelete()
$this->dispatch('/test/artist/' . $artist->getId());
$this->assertEquals(204, $this->getResponseStatusCode());

$this->assertEmpty($em->getRepository('Db\Entity\Artist')->find($id));
$this->assertEmpty($em->getRepository('ZFTestApigilityDb\Entity\Artist')->find($id));
$this->validateTriggeredEvents([DoctrineResourceEvent::EVENT_DELETE_PRE, DoctrineResourceEvent::EVENT_DELETE_POST]);

// Test DELETE: entity not found
Expand Down
Loading

0 comments on commit 0ef0114

Please sign in to comment.