Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviermarchegay committed Apr 25, 2024
1 parent 42a7293 commit 650343d
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 125 deletions.
1 change: 0 additions & 1 deletion src/Transformer/Xml/XpathEvaluatorTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public function buildXpath(\DOMNode $node): \DOMXPath

public function query(\DOMXPath $xpath, string $query, \DOMNode $node, array $options): mixed
{
// TODO check if query is relative ?
$nodeList = $xpath->query($query, $node);
$results = iterator_to_array($nodeList);

Expand Down
60 changes: 0 additions & 60 deletions tests.old/Transformer/XpathEvaluatorTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,66 +21,6 @@
*/
class XpathEvaluatorTransformerTest extends AbstractProcessTest
{
public function testSimpleQuery(): void
{
$domDocument = new \DOMDocument();
$domDocument->loadXML('<a>ok</a>');
$this->assertTransformation('xpath_evaluator', 'ok', $domDocument, [
'query' => '/a/text()',
]);
}

public function testAttributeValueQuery(): void
{
$domDocument = new \DOMDocument();
$domDocument->loadXML('<node data="ok">ko</node>');
$this->assertTransformation('xpath_evaluator', 'ok', $domDocument, [
'query' => '/node/@data',
]);
}

public function testSubQuery(): void
{
$domDocument = new \DOMDocument();
$domDocument->loadXML('<a><b><c>ok</c></b></a>');

$node = $domDocument->getElementsByTagName('b')[0];
$this->assertTransformation('xpath_evaluator', 'ok', $node, [
'query' => './c/text()',
]);
}

public function testMultiResults(): void
{
$domDocument = new \DOMDocument();
$domDocument->loadXML('<a><b><c>ok1</c><c>ok2</c><c>ok3</c></b></a>');

$node = $domDocument->getElementsByTagName('b')[0];
$this->assertTransformation('xpath_evaluator', ['ok1', 'ok2', 'ok3'], $node, [
'query' => './c/text()',
'single_result' => false,
]);
}

public function testMultiResultsAsNodeList(): void
{
$domDocument = new \DOMDocument();
$domDocument->loadXML('<a><b><c>ok1</c><c>ok2</c><c>ok3</c></b></a>');

$node = $domDocument->getElementsByTagName('b')[0];
/** @var \DOMNodeList $result */
$result = $this->transform('xpath_evaluator', $node, [
'query' => './c/text()',
'single_result' => false,
'unwrap_value' => false,
]);

self::assertCount(3, $result);
self::assertEquals('ok1', $result[0]->textContent);
self::assertEquals('ok2', $result[1]->textContent);
self::assertEquals('ok3', $result[2]->textContent);
}

public function testMultiQuery(): void
{
$domDocument = new \DOMDocument();
Expand Down
5 changes: 4 additions & 1 deletion tests/Exception/MissingTransformerExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use CleverAge\ProcessBundle\Exception\MissingTransformerException;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \CleverAge\ProcessBundle\Exception\MissingTransformerException
*/
class MissingTransformerExceptionTest extends TestCase
{
/**
* @covers \CleverAge\ProcessBundle\Exception\MissingTransformerException::create
* @covers ::create
*/
public function testCreate(): void
{
Expand Down
9 changes: 6 additions & 3 deletions tests/Transformer/ArrayElementTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @coversDefaultClass \CleverAge\ProcessBundle\Transformer\ArrayElementTransformer
*/
class ArrayElementTransformerTest extends TestCase
{
/**
* @covers \CleverAge\ProcessBundle\Transformer\ArrayElementTransformer::transform
* @covers ::transform
*/
public function testTransformReturnsNthElementFromArray(): void
{
Expand All @@ -34,7 +37,7 @@ public function testTransformReturnsNthElementFromArray(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\ArrayElementTransformer::configureOptions
* @covers ::configureOptions
*/
public function testConfigureOptionsSetsRequiredOptions(): void
{
Expand All @@ -50,7 +53,7 @@ public function testConfigureOptionsSetsRequiredOptions(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\ArrayElementTransformer::getCode
* @covers ::getCode
*/
public function testGetCodeReturnsCorrectCode(): void
{
Expand Down
13 changes: 8 additions & 5 deletions tests/Transformer/ArrayFirstTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @coversDefaultClass \CleverAge\ProcessBundle\Transformer\ArrayFirstTransformer
*/
class ArrayFirstTransformerTest extends TestCase
{
/**
* @covers \CleverAge\ProcessBundle\Transformer\ArrayFirstTransformer::transform
* @covers ::transform
*/
public function testTransformReturnsFirstElementIfIterableAndAllowed(): void
{
Expand All @@ -34,7 +37,7 @@ public function testTransformReturnsFirstElementIfIterableAndAllowed(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\ArrayFirstTransformer::transform
* @covers ::transform
*/
public function testTransformReturnsValueIfNotIterableAndAllowed(): void
{
Expand All @@ -50,7 +53,7 @@ public function testTransformReturnsValueIfNotIterableAndAllowed(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\ArrayFirstTransformer::transform
* @covers ::transform
*/
public function testTransformThrowsExceptionIfNotIterableAndNotAllowed(): void
{
Expand All @@ -64,7 +67,7 @@ public function testTransformThrowsExceptionIfNotIterableAndNotAllowed(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\ArrayFirstTransformer::getCode
* @covers ::getCode
*/
public function testGetCodeReturnsCorrectCode(): void
{
Expand All @@ -76,7 +79,7 @@ public function testGetCodeReturnsCorrectCode(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\ArrayFirstTransformer::configureOptions
* @covers ::configureOptions
*/
public function testConfigureOptionsSetsDefaultOptions(): void
{
Expand Down
17 changes: 10 additions & 7 deletions tests/Transformer/CastTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @coversDefaultClass \CleverAge\ProcessBundle\Transformer\CastTransformer
*/
class CastTransformerTest extends TestCase
{
/**
* @covers \CleverAge\ProcessBundle\Transformer\CastTransformer::transform
* @covers ::transform
*/
public function testCastToInt(): void
{
Expand All @@ -35,7 +38,7 @@ public function testCastToInt(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\CastTransformer::transform
* @covers ::transform
*/
public function testCastToFloat(): void
{
Expand All @@ -50,7 +53,7 @@ public function testCastToFloat(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\CastTransformer::transform
* @covers ::transform
*/
public function testCastToString(): void
{
Expand All @@ -65,7 +68,7 @@ public function testCastToString(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\CastTransformer::transform
* @covers ::transform
*/
public function testCastToBool(): void
{
Expand All @@ -80,7 +83,7 @@ public function testCastToBool(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\CastTransformer::transform
* @covers ::transform
*/
public function testCastToInvalidType(): void
{
Expand All @@ -94,7 +97,7 @@ public function testCastToInvalidType(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\CastTransformer::configureOptions
* @covers ::configureOptions
*/
public function testConfigureOptionsSetsRequiredOptions(): void
{
Expand All @@ -110,7 +113,7 @@ public function testConfigureOptionsSetsRequiredOptions(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\CastTransformer::getCode
* @covers ::getCode
*/
public function testGetCodeReturnsCorrectCode(): void
{
Expand Down
11 changes: 7 additions & 4 deletions tests/Transformer/ConstantTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @coversDefaultClass \CleverAge\ProcessBundle\Transformer\ConstantTransformer
*/
class ConstantTransformerTest extends TestCase
{
/**
* @covers \CleverAge\ProcessBundle\Transformer\ConstantTransformer::transform
* @covers ::transform
*/
public function testTransform(): void
{
Expand All @@ -34,7 +37,7 @@ public function testTransform(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\ConstantTransformer::transform
* @covers ::transform
*/
public function testTransformWithNullValue(): void
{
Expand All @@ -48,7 +51,7 @@ public function testTransformWithNullValue(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\ConstantTransformer::configureOptions
* @covers ::configureOptions
*/
public function testConfigureOptions(): void
{
Expand All @@ -61,7 +64,7 @@ public function testConfigureOptions(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\ConstantTransformer::getCode
* @covers ::getCode
*/
public function testGetCodeReturnsCorrectCode(): void
{
Expand Down
13 changes: 8 additions & 5 deletions tests/Transformer/DateFormatTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @coversDefaultClass \CleverAge\ProcessBundle\Transformer\DateFormatTransformer
*/
class DateFormatTransformerTest extends TestCase
{
/**
* @covers \CleverAge\ProcessBundle\Transformer\DateFormatTransformer::transform
* @covers ::transform
*/
public function testTransformValidDate(): void
{
Expand All @@ -35,7 +38,7 @@ public function testTransformValidDate(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\DateFormatTransformer::transform
* @covers ::transform
*/
public function testTransformInvalidDate(): void
{
Expand All @@ -49,7 +52,7 @@ public function testTransformInvalidDate(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\DateFormatTransformer::transform
* @covers ::transform
*/
public function testTransformNullValue(): void
{
Expand All @@ -64,7 +67,7 @@ public function testTransformNullValue(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\DateFormatTransformer::getCode
* @covers ::getCode
*/
public function testGetCode(): void
{
Expand All @@ -76,7 +79,7 @@ public function testGetCode(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\DateFormatTransformer::configureOptions
* @covers ::configureOptions
*/
public function testConfigureOptions(): void
{
Expand Down
15 changes: 9 additions & 6 deletions tests/Transformer/DateParserTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @coversDefaultClass \CleverAge\ProcessBundle\Transformer\DateParserTransformer
*/
class DateParserTransformerTest extends TestCase
{
/**
* @covers \CleverAge\ProcessBundle\Transformer\DateParserTransformer::transform
* @covers ::transform
*/
public function testTransformValidDate(): void
{
Expand All @@ -35,7 +38,7 @@ public function testTransformValidDate(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\DateParserTransformer::transform
* @covers ::transform
*/
public function testTransformInvalidDate(): void
{
Expand All @@ -49,7 +52,7 @@ public function testTransformInvalidDate(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\DateParserTransformer::transform
* @covers ::transform
*/
public function testTransformNullValue(): void
{
Expand All @@ -63,7 +66,7 @@ public function testTransformNullValue(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\DateParserTransformer::transform
* @covers ::transform
*/
public function testTransformDateTimeObject(): void
{
Expand All @@ -78,7 +81,7 @@ public function testTransformDateTimeObject(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\DateParserTransformer::getCode
* @covers ::getCode
*/
public function testGetCode(): void
{
Expand All @@ -90,7 +93,7 @@ public function testGetCode(): void
}

/**
* @covers \CleverAge\ProcessBundle\Transformer\DateParserTransformer::configureOptions
* @covers ::configureOptions
*/
public function testConfigureOptions(): void
{
Expand Down
Loading

0 comments on commit 650343d

Please sign in to comment.