Skip to content

Commit

Permalink
Merge pull request #20 from GeometriaLab/feature/controllerTests
Browse files Browse the repository at this point in the history
Remove CleanupDatabases plugin.
  • Loading branch information
shumkov committed Nov 26, 2012
2 parents dc96042 + aec9a89 commit a14f92d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
16 changes: 12 additions & 4 deletions library/GeometriaLab/Api/Mvc/View/Http/CreateApiModelListener.php
Expand Up @@ -4,15 +4,13 @@

use GeometriaLab\Model\ModelInterface,
GeometriaLab\Model\CollectionInterface,
GeometriaLab\Model\Schema\SchemaInterface,
GeometriaLab\Api\Mvc\View\Model\ApiModel,
GeometriaLab\Api\Paginator\ModelPaginator,
GeometriaLab\Api\Exception\InvalidFieldsException,
GeometriaLab\Api\Mvc\Controller\Action\Params\AbstractParams,
GeometriaLab\Api\Mvc\Controller\Action\Params\Schema\Property\IntegerProperty as ParamsIntegerProperty;
GeometriaLab\Api\Exception\InvalidFieldsException;

use Zend\Mvc\MvcEvent as ZendMvcEvent,
Zend\Mvc\View\Http\InjectViewModelListener as ZendInjectViewModelListener,
Zend\Http\PhpEnvironment\Response,
Zend\EventManager\ListenerAggregateInterface as ZendListenerAggregateInterface,
Zend\EventManager\EventManagerInterface as ZendEvents,
Zend\Validator\LessThan as ZendLessThanValidator,
Expand Down Expand Up @@ -78,9 +76,19 @@ public function createApiModel(ZendMvcEvent $e)
$apiModel->setVariable(ApiModel::FIELD_DATA, null);
}

/* @var Response $response */
$response = $e->getResponse();
$apiException = $e->getParam('apiException', false);

if ($response->getStatusCode() === Response::STATUS_CODE_200) {
if ($apiModel->getVariable(ApiModel::FIELD_DATA) === null) {
$response->setStatusCode(Response::STATUS_CODE_204);
}
if ($e->getRouteMatch()->getParam('action') === 'create') {
$response->setStatusCode(Response::STATUS_CODE_201);
}
}

// set http code
$httpCode = $response->getStatusCode();
$apiModel->setVariable(ApiModel::FIELD_HTTPCODE, $httpCode);
Expand Down
20 changes: 10 additions & 10 deletions library/GeometriaLab/Mongo/Model/Mapper.php
Expand Up @@ -513,6 +513,16 @@ public function createQuery()
return new Query($this);
}

/**
* Get MongoCollection
*
* @return \MongoCollection
*/
public function getMongoCollection()
{
return $this->getMongo()->selectCollection($this->getCollectionName());
}

/**
* Set Service Manager
*
Expand Down Expand Up @@ -565,14 +575,4 @@ protected function getMongo()
{
return self::$serviceManager->get('MongoManager')->get($this->getMongoInstanceName());
}

/**
* Get MongoCollection
*
* @return \MongoCollection
*/
protected function getMongoCollection()
{
return $this->getMongo()->selectCollection($this->getCollectionName());
}
}
Expand Up @@ -37,7 +37,7 @@ public function getTest()
/**
* It will call when a test ended
*/
public function tearDown()
public function endTest()
{

}
Expand Down
Expand Up @@ -24,5 +24,5 @@ public function getTest();
/**
* It will call when a test ended
*/
public function tearDown();
public function endTest();
}
4 changes: 2 additions & 2 deletions library/GeometriaLab/Test/PHPUnit/Plugin/PluginListener.php
Expand Up @@ -121,8 +121,8 @@ public function endTest(\PHPUnit_Framework_Test $test, $time)
}
foreach ($plugins as $pluginName) {
$plugin = $test->getPluginManager()->get($pluginName);
if (method_exists($plugin, 'tearDown')) {
$plugin->tearDown();
if (method_exists($plugin, 'endTest')) {
$plugin->endTest();
}
}
}
Expand Down

0 comments on commit a14f92d

Please sign in to comment.