Skip to content
Permalink
Browse files

unittest + codestyle fixes

  • Loading branch information...
lugark committed Nov 6, 2019
1 parent 2cea81d commit 1dc87434e2ef35cd8aed353c498568dc4241ca3b
@@ -216,10 +216,7 @@ public function getDataTransformator()
return $this->dataTransformator;
}
/**
* @param DataTransformerInterface $dataTransformator
*/
public function setDataTransformator($dataTransformator)
public function setDataTransformator(DataTransformerInterface $dataTransformator)
{
$this->dataTransformator = $dataTransformator;
}
@@ -1,10 +1,27 @@
<?php
namespace Tests\PHPCensor\Form\DataTransformer;
use PHPCensor\Form\DataTransformer\Yaml;
use PHPUnit\Framework\TestCase;
class YamlDataTransformerTest
class YamlDataTransformerTest extends TestCase
{
public $textToTransform = 'some_unchanged_text transformed to be displayed in forms';
public $textForReverseTransform = "some_text_with_tabs\t and \tanother\tone";
public $textAfterReverseTransform = "some_text_with_tabs\t and \tanother\tone";
public function testTransform()
{
$transformer = new Yaml();
$this->assertEquals($this->textToTransform, $transformer->transform($this->textToTransform));
$this->assertEquals($this->textForReverseTransform, $transformer->transform($this->textForReverseTransform));
}
public function testReverveTransform()
{
$transformer = new Yaml();
$this->assertEquals($this->textToTransform, $transformer->reverseTransform($this->textToTransform));
$this->assertEquals($this->textAfterReverseTransform, $transformer->transform($this->textForReverseTransform));
}
}
@@ -1,10 +1,51 @@
<?php
namespace Tests\PHPCensor\Form;
use PHPCensor\Form\DataTransformer\Yaml;
use PHPCensor\Form\Input;
use PHPUnit\Framework\TestCase;
class FormInputTest
class FormInputTest extends TestCase
{
/** @var Input $inputElement */
private $inputElement;
public function setUp()
{
parent::setUp();
$this->inputElement = Input::create('test', 'Test');
}
public function tearDown()
{
$this->inputElement = null;
parent::tearDown();
}
public function testValidatorSetterGetterSuccess()
{
$validator = function ($value) { echo $value;};
$this->inputElement->setValidator($validator);
$this->assertEquals($validator, $this->inputElement->getValidator());
}
public function testValidatorSetFail()
{
$this->inputElement->setValidator(5);
$this->assertNull($this->inputElement->getValidator());
}
public function testGetValue()
{
$this->inputElement->setValue(5);
$this->assertEquals(5, $this->inputElement->getValue());
}
public function testGetValueWithDatatransformer()
{
$this->inputElement->setDataTransformator(new Yaml());
$this->inputElement->setValue("key\t=>\tvalue");
$this->assertEquals('key => value', $this->inputElement->getValue());
}
}
@@ -1,10 +1,47 @@
<?php
namespace Tests\PHPCensor\Form\Validator;
use PHPCensor\Form\Validator\Yaml;
use PHPUnit\Framework\TestCase;
class YamlValidatorTest
class YamlValidatorTest extends TestCase
{
public function getDatasetSuccess()
{
return [
["php-censor:\n language: en\n per_page: 10\n\n"],
["build_settings:\n clone_depth: 1\n\nsetup:\n composer:\n action: \"install\"\n directory: \"core/libraries\""],
["{ }"]
];
}
public function getDatasetFail()
{
return [
["php-censor:\n language: en\n per_page: 10\n\n"],
["php-censor:\n\tlanguage: en\n per_page: 10\n\n"],
["php-censor:\n\tlanguage: en\n\tper_page: 10\n\n"],
];
}
/**
* @dataProvider getDatasetSuccess
*/
public function testYamlValidatorSuccess($value)
{
$validator = new Yaml();
$result = call_user_func_array($validator, [$value]);
$this->assertTrue($result);
}
/**
* @dataProvider getDatasetFail
*/
public function testYamlValidatorFail($value)
{
$this->expectException('Exception');
$validator = new Yaml();
call_user_func_array($validator, [$value]);
}
}

0 comments on commit 1dc8743

Please sign in to comment.
You can’t perform that action at this time.