Skip to content

Commit

Permalink
Smart Endpoint Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelJ2324 committed Mar 23, 2017
1 parent 2db83c8 commit e7ba8d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Endpoint/Abstracts/AbstractSmartEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace MRussell\REST\Endpoint\Abstracts;

use MRussell\REST\Endpoint\Data\AbstractEndpointData;
use MRussell\REST\Exception\Endpoint\EndpointException;
use MRussell\REST\Exception\Endpoint\InvalidDataType;

abstract class AbstractSmartEndpoint extends AbstractEndpoint
{
Expand Down Expand Up @@ -80,7 +80,7 @@ public function setData($data) {
$this->data->reset();
$this->data->update($data);
} else {
throw new EndpointException("Invalid data passed to Endpoint");
throw new InvalidDataType(get_class($this));
}
return $this;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Exception/Endpoint/InvalidDataType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace MRussell\REST\Exception\Endpoint;


class InvalidDataType extends EndpointException
{
protected $message = 'Invalid data type passed to Endpoint [%s]';
}
20 changes: 20 additions & 0 deletions tests/Endpoint/AbstractSmartEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace MRussell\REST\Tests\Endpoint;

use MRussell\REST\Endpoint\Data\EndpointData;
use MRussell\REST\Tests\Stubs\Endpoint\SmartEndpoint;


Expand Down Expand Up @@ -117,11 +118,30 @@ public function testSetProperties(){

/**
* @covers ::setData
* @covers ::getData
* @covers ::configureData
*/
public function testSetData(){
$Endpoint = new SmartEndpoint();
$Data = new EndpointData();
$this->assertEquals($Endpoint,$Endpoint->setData($Data));
$this->assertEquals($Data,$Endpoint->getData());

$this->assertEquals($Endpoint,$Endpoint->setData(array('foo' => 'bar')));
$this->assertEquals(array('foo' => 'bar'),$Endpoint->getData()->asArray());

$Class = new \ReflectionClass('MRussell\REST\Endpoint\Abstracts\AbstractSmartEndpoint');
$method = $Class->getMethod('configureData');
$method->setAccessible(TRUE);
$this->assertEquals(array('foo' => 'bar'),$method->invoke($Endpoint,$Endpoint->getData()));
}

/**
* @expectedException MRussell\REST\Exception\Endpoint\InvalidDataType
*/
public function testInvalidDataType(){
$Endpoint = new SmartEndpoint();
$Endpoint->setData('test');
}

}

0 comments on commit e7ba8d1

Please sign in to comment.