Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Apr 2, 2014
1 parent 769a163 commit 3bfdfa6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
36 changes: 36 additions & 0 deletions tests/ZfrRestTest/Asset/Mvc/ControllerWithValidationGroupSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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.
*/

namespace ZfrRestTest\Asset\Mvc;


use ZfrRest\Mvc\Controller\AbstractRestfulController;
use ZfrRest\Mvc\Controller\ValidationGroupProviderInterface;

class ControllerWithValidationGroupSpec extends AbstractRestfulController implements ValidationGroupProviderInterface
{
/**
* {@inheritDoc}
*/
public function getValidationGroupSpecification()
{
return [
'post' => ['field']
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use PHPUnit_Framework_TestCase;
use ZfrRest\Options\ControllerBehavioursOptions;
use ZfrRestTest\Asset\Mvc\ControllerWithValidationGroupSpec;
use ZfrRestTest\Asset\Mvc\DataValidationObject;

/**
Expand Down Expand Up @@ -120,18 +121,12 @@ public function testThrowExceptionOnFailedValidation()

public function testCanUseValidationGroup()
{
$controller = $this->getMock('ZfrRest\Mvc\Controller\AbstractRestfulController');

$resource = $this->getMock('ZfrRest\Resource\ResourceInterface');
$metadata = $this->getMock('ZfrRest\Resource\Metadata\ResourceMetadataInterface');

$resource->expects($this->once())->method('getMetadata')->will($this->returnValue($metadata));
$metadata->expects($this->once())->method('getInputFilterName')->will($this->returnValue('inputFilter'));

$controller->expects($this->once())
->method('getValidationGroupSpecification')
->will($this->returnValue(['post' => ['field']]));

$data = ['foo'];

$inputFilter = $this->getMock('Zend\InputFilter\InputFilterInterface');
Expand All @@ -153,6 +148,8 @@ public function testCanUseValidationGroup()
->method('getValues')
->will($this->returnValue(['filtered']));

$controller = new ControllerWithValidationGroupSpec();

$result = $this->dataValidation->validateData($resource, $data, $controller, 'post');

$this->assertEquals(['filtered'], $result);
Expand Down

0 comments on commit 3bfdfa6

Please sign in to comment.