Skip to content

Commit

Permalink
test(document): unit test plugin document
Browse files Browse the repository at this point in the history
  • Loading branch information
VEBERArnaud committed Feb 17, 2017
1 parent e3386c9 commit f3007e0
Showing 1 changed file with 233 additions and 0 deletions.
233 changes: 233 additions & 0 deletions tests/Document/PluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
<?php

/*
* This file is part of the KongAdminApi package.
*
* (c) Unikorp <https://github.com/unikorp>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Unikorp\KongAdminApi\Tests\Document;

use Unikorp\KongAdminApi\Document\Plugin as Document;

/**
* plugin test
*
* @author VEBER Arnaud <https://github.com/VEBERArnaud>
*/
class PluginTest extends \PHPUnit_Framework_TestCase
{
/**
* document
* @var \Unikorp\KongAdminApi\Document\Plugin $document
*/
private $document = null;

/**
* set up
*
* @return void
*
* @coversNothing
*/
protected function setUp()
{
$this->document = new Document();
}

/**
* tear down
*
* @return void
*
* @coversNothing
*/
protected function tearDown()
{
$this->document = null;
}

/**
* test set name
*
* @return void
*
* @covers \Unikorp\KongAdminApi\Document\Plugin::setName
*/
public function testSetName()
{
// reflect `document`
$reflectionClass = new \ReflectionClass($this->document);

// set `name` property from `document` accessible
$reflectionProperty = $reflectionClass->getProperty('name');
$reflectionProperty->setAccessible(true);

// asserts
$this->document->setName('test');
$this->assertSame('test', $reflectionProperty->getValue($this->document));
}

/**
* test get name
*
* @return void
*
* @covers \Unikorp\KongAdminApi\Document\Plugin::getName
*/
public function testGetName()
{
// reflect `document`
$reflectionClass = new \ReflectionClass($this->document);

// set `name` property from `document` accessible
$reflectionProperty = $reflectionClass->getProperty('name');
$reflectionProperty->setAccessible(true);

// assert
$reflectionProperty->setValue($this->document, 'test');
$this->assertSame('test', $this->document->getName());
}

/**
* test set consumer id
*
* @return void
*
* @covers \Unikorp\KongAdminApi\Document\Plugin::setConsumerId
*/
public function testSetConsumerId()
{
// reflect `document`
$reflectionClass = new \ReflectionClass($this->document);

// set `consumer id` property from `document` accessible
$reflectionProperty = $reflectionClass->getProperty('consumerId');
$reflectionProperty->setAccessible(true);

// asserts
$this->document->setConsumerId('test');
$this->assertSame('test', $reflectionProperty->getValue($this->document));
}

/**
* test get consumer id
*
* @return void
*
* @covers \Unikorp\KongAdminApi\Document\Plugin::getConsumerId
*/
public function testGetConsumerId()
{
// reflect `document`
$reflectionClass = new \ReflectionClass($this->document);

// set `consumer id` property from `document` accessible
$reflectionProperty = $reflectionClass->getProperty('consumerId');
$reflectionProperty->setAccessible(true);

// assert
$reflectionProperty->setValue($this->document, 'test');
$this->assertSame('test', $this->document->getConsumerId());
}

/**
* test add config
*
* @return void
*
* @covers \Unikorp\KongAdminApi\Document\Plugin::addConfig
*/
public function testAddConfig()
{
// reflect `document`
$reflectionClass = new \ReflectionClass($this->document);

// set `config` property from `document` accessible
$reflectionProperty = $reflectionClass->getProperty('config');
$reflectionProperty->setAccessible(true);

// assert
$this->document
->addConfig('test', 'test')
->addConfig('something_else', 'something_else');
$this->assertSame(
['test' => 'test', 'something_else' => 'something_else'],
$reflectionProperty->getValue($this->document)
);
}

/**
* test remove config
*
* @return void
*
* @covers \Unikorp\KongAdminApi\Document\Plugin::removeConfig
*/
public function testRemoveConfig()
{
// reflect `document`
$reflectionClass = new \ReflectionClass($this->document);

// set `config` property from `document` accessible
$reflectionProperty = $reflectionClass->getProperty('config');
$reflectionProperty->setAccessible(true);

$reflectionProperty->setValue(
$this->document,
['test' => 'test', 'something_else' => 'something_else']
);

// assert
$this->document->removeConfig('test');
$this->assertSame(['something_else' => 'something_else'], $reflectionProperty->getValue($this->document));
}

/**
* test get config
*
* @return void
*
* @covers \Unikorp\KongAdminApi\Document\Plugin::getConfig
*/
public function testGetConfig()
{
// reflect `document`
$reflectionClass = new \ReflectionClass($this->document);

// set `config` property from `document` accessible
$reflectionProperty = $reflectionClass->getProperty('config');
$reflectionProperty->setAccessible(true);

$reflectionProperty->setValue($this->document, ['test' => 'test']);

// assert
$this->assertSame('test', $this->document->getConfig('test'));
}

/**
* test to json
*
* @return void
*
* @covers \Unikorp\KongAdminApi\AbstractDocument::toJson
* @covers \Unikorp\KongAdminApi\Document\Plugin::getFields
* @covers \Unikorp\KongAdminApi\AbstractDocument::toSnakeCase
*/
public function testToJson()
{
$this->document
->setName('name')
->setConsumerId('consumerId')
->addConfig('test', true)
->addConfig('something_else', 'something_else');

$this->assertSame(
'{"name":"name","consumer_id":"consumerId","config.test":true,"config.something_else":"something_else"}',
$this->document->toJson()
);
}
}

0 comments on commit f3007e0

Please sign in to comment.