Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Basic PHPUnit test skeleton for Convertor
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Feb 21, 2019
1 parent 5a2d11c commit 33c378b
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 19 deletions.
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<phpunit colors="true" bootstrap="./tests/bootstrap.php">
<testsuites>
<testsuite name="all">
<directory>./tests/FlexiPeeHP</directory>
<directory>./tests/src/FlexiPeeHP</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">FlexiPeeHP</directory>
<directory suffix=".php">src/FlexiPeeHP</directory>
</whitelist>
</filter>

Expand Down
47 changes: 30 additions & 17 deletions src/FlexiPeeHP/Bricks/Convertor.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function __construct(\FlexiPeeHP\FlexiBeeRO $input = null,
}

/**
* Set Source Documnet
*
* @param \FlexiPeeHP\FlexiBeeRO $source
*/
Expand All @@ -61,6 +62,7 @@ public function setSource(\FlexiPeeHP\FlexiBeeRO $source)
}

/**
* Set Destination document
*
* @param \FlexiPeeHP\FlexiBeeRO $destinantion
*/
Expand Down Expand Up @@ -141,18 +143,19 @@ public function prepareRules()
break;
default :
throw new \Ease\Exception(sprintf(_('Unsupported Source document type %s'),
get_class($this->output)));
get_class($this->output)));
break;
}
break;
default:
throw new \Ease\Exception(sprintf(_('Unsupported Source document type %s'),
get_class($this->input)));
get_class($this->input)));
break;
}
}

/**
* Convert FlexiBee document
*
* @param boolean $keepId keep item IDs
* @param boolean $addExtId add ext:originalEvidence:originalId
Expand All @@ -165,18 +168,7 @@ public function convertDocument($keepId = false, $addExtId = false,
}

/**
*
* @param boolean $keepId keep item IDs
* @param boolean $addExtId add ext:originalEvidence:originalId
* @param boolean $keepCode keep items code
*/
public function convertDocument($keepId = false, $addExtId = false,
$keepCode = false)
{
$this->convertItems($keepId, $addExtId, $keepCode);
}

/**
* Convert FlexiBee documnet's subitems
*
* @param string $columnToTake usually "polozkyDokladu"
* @param boolean $keepId keep item IDs
Expand Down Expand Up @@ -235,7 +227,7 @@ public function convertItems($keepId = false, $addExtId = true,
}
foreach (self::removeRoColumns($this->rules, $this->output) as $columnToTake => $subitemColumns) {
if (is_array($subitemColumns)) {
if(!empty($this->input->getSubItems())){
if (!empty($this->input->getSubItems())) {
$this->convertSubitems($columnToTake, $keepId, $keepCode);
}
} else {
Expand All @@ -257,9 +249,9 @@ public function convertItems($keepId = false, $addExtId = true,
*/
public static function removeRoColumns(array $rules, $engine)
{
foreach ($rules as $index=>$subrules) {
foreach ($rules as $index => $subrules) {
if (is_array($subrules)) {
$eback = $engine->getEvidence();
$eback = $engine->getEvidence();
$engine->setEvidence($engine->getEvidence().'-polozka');
$rules[$index] = self::removeRoColumns($subrules, $engine);
$engine->setEvidence($eback);
Expand All @@ -274,6 +266,7 @@ public static function removeRoColumns(array $rules, $engine)
}

/**
* Return itemes that same on both sides
*
* @return array
*/
Expand All @@ -282,4 +275,24 @@ public function commonItems()
return array_intersect(array_keys($this->input->getColumnsInfo()),
array_keys($this->output->getColumnsInfo()));
}

/**
* Get input object here
*
* @return \FlexiPeeHP\FlexiBeeRO
*/
public function getInput()
{
return $this->input;
}

/**
* Get output object here
*
* @return \FlexiPeeHP\FlexiBeeRO
*/
public function getOutput()
{
return $this->output;
}
}
164 changes: 164 additions & 0 deletions tests/src/FlexiPeeHP/Bricks/ConvertorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

namespace Test\FlexiPeeHP\Bricks;

use \FlexiPeeHP\Bricks\Convertor;

/**
* Generated by PHPUnit_SkeletonGenerator on 2019-02-21 at 12:27:19.
*/
class ConvertorTest extends \Test\Ease\SandTest
{
/**
* @var Convertor
*/
protected $object;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new Convertor();
}

/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{

}

/**
* @covers FlexiPeeHP\Bricks\Convertor::setSource
*/
public function testSetSource()
{
$sourcer = new \FlexiPeeHP\FakturaVydana();
$this->object->setSource($sourcer);
$this->assertEquals($sourcer, $this->object->getInput());
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::setDestination
*/
public function testSetDestination()
{
$dester = new \FlexiPeeHP\FakturaPrijata();
$this->object->setDestination($dester);
$this->assertEquals($dester, $this->object->getOutput());
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::conversion
* @expectedException \Ease\Exception
*/
public function testConversion()
{
$this->object->conversion();
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::baseClassName
*/
public function testBaseClassName()
{
$this->assertEquals('FakturaVydana',
$this->object->baseClassName(new \FlexiPeeHP\FakturaVydana()));
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::prepareRules
* @todo Implement testPrepareRules().
*/
public function testPrepareRules()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::convertDocument
* @todo Implement testConvertDocument().
*/
public function testConvertDocument()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::convertSubitems
* @todo Implement testConvertSubitems().
*/
public function testConvertSubitems()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::convertItems
* @todo Implement testConvertItems().
*/
public function testConvertItems()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::removeRoColumns
* @todo Implement testRemoveRoColumns().
*/
public function testRemoveRoColumns()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::commonItems
* @todo Implement testCommonItems().
*/
public function testCommonItems()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::getInput
*/
public function testGetInput()
{
$test = new \FlexiPeeHP\Adresar();
$this->object->setSource($test);
$this->assertEquals($test, $this->object->getInput());
}

/**
* @covers FlexiPeeHP\Bricks\Convertor::getOutput
*/
public function testGetOutput()
{
$test = new \FlexiPeeHP\Adresar();
$this->object->setDestination($test);
$this->assertEquals($test, $this->object->getOutput());
}
}

0 comments on commit 33c378b

Please sign in to comment.