Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#BPI-71 by Inlead: Fixing tests #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions Bpi/Sdk/Authorization.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php
namespace Bpi\Sdk;

/**
* Class Authorization
* Prepare authorization credentials.
*
* @package Bpi\Sdk
*/
class Authorization
{
protected $agency_id;
Expand Down
7 changes: 6 additions & 1 deletion Bpi/Sdk/Bpi.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
require_once __DIR__ . '/../../vendor/autoload.php';


/**
* Class Bpi
* Bpi client.
*/
class Bpi
{
/**
Expand Down Expand Up @@ -80,7 +85,7 @@ public function searchNodes(array $queries = array())
/**
* Push new node to BPI
*
* @param array $data
* @param array $data of node which will be pushed to service.
* @throws \InvalidArgumentException
* @return \Bpi\Sdk\Item\Node
*/
Expand Down
7 changes: 6 additions & 1 deletion Bpi/Sdk/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
use Goutte\Client;
use Symfony\Component\DomCrawler\Crawler;

/**
* Class Document
*
* @package Bpi\Sdk
*/
class Document implements \Iterator, \Countable
{
/**
Expand Down Expand Up @@ -229,7 +234,7 @@ public function walkProperties($callback)
{
$crawler = new Crawler($this->crawler->current());
return $crawler->filter('item property')->each(function($e) use($callback) {
$sxml = simplexml_import_dom($e);
$sxml = simplexml_import_dom($e->getNode(0));
$callback(current($sxml->attributes()) + array('@value' => (string) $sxml));
});
}
Expand Down
5 changes: 5 additions & 0 deletions Bpi/Sdk/Exception/EmptyList.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
namespace Bpi\Sdk\Exception;

/**
* Class EmptyList
*
* @package Bpi\Sdk\Exception
*/
class EmptyList extends SDKException {}
6 changes: 6 additions & 0 deletions Bpi/Sdk/Exception/HTTP/ClientError.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
namespace Bpi\Sdk\Exception\HTTP;

/**
* Class ClientError
* Exception class for client errors.
*
* @package Bpi\Sdk\Exception\HTTP
*/
class ClientError extends Error {}
6 changes: 6 additions & 0 deletions Bpi/Sdk/Exception/HTTP/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@

use Bpi\Sdk\Exception\SDKException;

/**
* Class Error
* Error exception class.
*
* @package Bpi\Sdk\Exception\HTTP
*/
class Error extends SDKException {}
6 changes: 6 additions & 0 deletions Bpi/Sdk/Exception/HTTP/ServerError.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
namespace Bpi\Sdk\Exception\HTTP;

/**
* Class ServerError
* Exception class for server errors.
*
* @package Bpi\Sdk\Exception\HTTP
*/
class ServerError extends Error {}
6 changes: 6 additions & 0 deletions Bpi/Sdk/Exception/InvalidQueryParameter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
namespace Bpi\Sdk\Exception;

/**
* Class InvalidQueryParameter
* Exception class for query errors.
*
* @package Bpi\Sdk\Exception
*/
class InvalidQueryParameter extends SDKException {}
6 changes: 6 additions & 0 deletions Bpi/Sdk/Exception/SDKException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
namespace Bpi\Sdk\Exception;

/**
* Class SDKException
* Main exception class.
*
* @package Bpi\Sdk\Exception
*/
class SDKException extends \Exception {}
6 changes: 6 additions & 0 deletions Bpi/Sdk/Exception/UndefinedHypermedia.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
namespace Bpi\Sdk\Exception;

/**
* Class UndefinedHypermedia
* Exception class for hypermedia errors.
*
* @package Bpi\Sdk\Exception
*/
class UndefinedHypermedia extends SDKException {}
5 changes: 5 additions & 0 deletions Bpi/Sdk/Item/BaseItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

use Bpi\Sdk\Document;

/**
* Class BaseItem
*
* @package Bpi\Sdk\Item
*/
class BaseItem
{
protected $document;
Expand Down
6 changes: 6 additions & 0 deletions Bpi/Sdk/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

use Symfony\Component\DomCrawler\Crawler;

/**
* Class Link
* Prepare URI for request.
*
* @package Bpi\Sdk
*/
class Link
{
/**
Expand Down
6 changes: 6 additions & 0 deletions Bpi/Sdk/NodeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

use Bpi\Sdk\Document;

/**
* Class NodeList
* Interact with list of nodes.
*
* @package Bpi\Sdk
*/
class NodeList implements \Iterator, \Countable
{
/**
Expand Down
6 changes: 6 additions & 0 deletions Bpi/Sdk/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

use Symfony\Component\DomCrawler\Crawler;

/**
* Class Query
* Prepare query.
*
* @package Bpi\Sdk
*/
class Query
{
/**
Expand Down
7 changes: 6 additions & 1 deletion Bpi/Sdk/ResponseStatus.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
namespace Bpi\Sdk;

/**
* Class ResponseStatus
* Check status of response.
*
* @package Bpi\Sdk
*/
class ResponseStatus
{
protected $status;
Expand Down
5 changes: 5 additions & 0 deletions Bpi/Sdk/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

use Symfony\Component\DomCrawler\Crawler;

/**
* Class Template
*
* @package Bpi\Sdk
*/
class Template
{
/**
Expand Down
5 changes: 5 additions & 0 deletions Bpi/Sdk/Template/Field.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
namespace Bpi\Sdk\Template;

/**
* Class Field
*
* @package Bpi\Sdk\Template
*/
class Field
{
/**
Expand Down
2 changes: 2 additions & 0 deletions Tests/Unit/Fixtures/Collection.bpi
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
</hypermedia>
<property name="title">COLLECTION_TITLE</property>
<property name="teaser">COLLECTION_TEASER</property>
<property name="syndicated">4</property>
</item>
<item type="entity">
<hypermedia>
<link rel="self" href="" />
</hypermedia>
<property name="title">COLLECTION_TITLE_BRAVO</property>
<property name="teaser">COLLECTION_TEASER_BRAVO</property>
<property name="syndicated">4</property>
</item>
</bpi>
1 change: 1 addition & 0 deletions Tests/Unit/Fixtures/Node.bpi
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</template>
</hypermedia>
<property name="title">TITLE</property>
<property name="syndicated">1</property>
<property name="teaser">TEASER</property>
</item>
</bpi>
2 changes: 1 addition & 1 deletion Tests/Unit/IteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testReduceItemsByAttr()

try
{
$doc->reduceItemsByAttr(mt_rand(), 'node');
$doc->reduceItemsByAttr('node', mt_rand());
$this->fail('Exception expected trying reduce items by non existing attribute');
} catch (Exception\EmptyList $e) {
$this->assertTrue(true);
Expand Down
16 changes: 11 additions & 5 deletions Tests/Unit/PropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public function testWalkProperties()

$this->assertEquals('title', $properties[0]['name']);
$this->assertEquals('TITLE', $properties[0]['@value']);
$this->assertEquals('teaser', $properties[1]['name']);
$this->assertEquals('TEASER', $properties[1]['@value']);
$this->assertEquals('syndicated', $properties[1]['name']);
$this->assertEquals('1', $properties[1]['@value']);
$this->assertEquals('teaser', $properties[2]['name']);
$this->assertEquals('TEASER', $properties[2]['@value']);
}

public function testGetPropertiesFromCollection()
{
$doc = $this->createMockDocument('Collection');
Expand Down Expand Up @@ -65,6 +67,8 @@ public function testGetPropertiesFromCollection()
$this->assertEquals('COLLECTION_TITLE', $properties[0]['@value']);
$this->assertEquals('teaser', $properties[1]['name']);
$this->assertEquals('COLLECTION_TEASER', $properties[1]['@value']);
$this->assertEquals('syndicated', $properties[2]['name']);
$this->assertEquals('4', $properties[2]['@value']);

break;
case 2: break;
Expand All @@ -91,11 +95,13 @@ public function testPropertiesWhileIterating()
}

$this->assertEquals($doc->count(), count($items));
$this->assertEquals(2, count($items[0]));
$this->assertEquals(2, count($items[1]));
$this->assertEquals(3, count($items[0]));
$this->assertEquals(3, count($items[1]));
$this->assertEquals('COLLECTION_TITLE', $items[0][0]['@value']);
$this->assertEquals('COLLECTION_TEASER', $items[0][1]['@value']);
$this->assertEquals('4', $items[0][2]['@value']);
$this->assertEquals('COLLECTION_TITLE_BRAVO', $items[1][0]['@value']);
$this->assertEquals('COLLECTION_TEASER_BRAVO', $items[1][1]['@value']);
$this->assertEquals('4', $items[1][2]['@value']);
}
}
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
],
"require": {
"php": ">=5.3.3",
"doctrine/common": "2.3.0",
"fabpot/goutte": "v1.0.1"
"fabpot/goutte": "~1.0"
},
"autoload": {
"psr-0": { "Bpi\\Sdk": "." }
Expand Down
Loading