This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
<?php
namespace Ddeboer\DataImport\Tests\Step;
use Ddeboer\DataImport\Step\ConverterStep;
class ConverterStepTest extends \PHPUnit_Framework_TestCase
{
private $step;
protected function setUp()
{
$this->step = new ConverterStep();
}
public function testProcess()
{
$this->step->add(function() { return ['bar']; });
$data = ['foo'];
$this->step->process($data);
$this->assertEquals(['bar'], $data);
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Ddeboer\DataImport\Tests\Step;
use Ddeboer\DataImport\Step\FilterStep;
class FilterStepTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->filter = new FilterStep();
}
public function testProcess()
{
$this->filter->add(function ($v) { return in_array('bar', $v); });
$d = ['foo'];
$this->assertFalse($this->filter->process($d));
$d = ['bar'];
$this->assertTrue($this->filter->process($d));
}
public function testClone()
{
$reflection = new \ReflectionObject($this->filter);
$property = $reflection->getProperty('filters');
$property->setAccessible(true);
$this->filter->add(function ($v) { return in_array('bar', $v); });
$d = ['foo'];
$this->filter->process($d);
$this->assertCount(1, $property->getValue($this->filter));
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Ddeboer\DataImport\Tests\Step;
use Ddeboer\DataImport\Step\MappingStep;
class MappingStepTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->filter = new MappingStep();
}
public function testProcess()
{
$this->filter->map('[foo]', '[bar]');
$data = [
'foo' => '1',
];
$this->filter->process($data);
$this->assertEquals(['bar' => '1'], $data);
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace Ddeboer\DataImport\Tests\Step;
use Ddeboer\DataImport\Step\ValidatorStep;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
class ValidatorStepTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
$this->filter = new ValidatorStep($this->validator);
}
public function testProcess()
{
$data = ['title' => null];
$this->filter->add('title', $constraint = new Constraints\NotNull());
$list = new ConstraintViolationList();
$list->add($this->buildConstraintViolation());
$this->validator->expects($this->once())
->method('validate')
->willReturn($list);
$this->assertFalse($this->filter->process($data));
$this->assertEquals([1 => $list], $this->filter->getViolations());
}
/**
* @expectedException Ddeboer\DataImport\Exception\ValidationException
*/
public function testProcessWithExceptions()
{
$data = ['title' => null];
$this->filter->add('title', $constraint = new Constraints\NotNull());
$this->filter->throwExceptions();
$list = new ConstraintViolationList();
$list->add($this->buildConstraintViolation());
$this->validator->expects($this->once())
->method('validate')
->willReturn($list);
$this->assertFalse($this->filter->process($data));
}
public function testPriority()
{
$this->assertEquals(128, $this->filter->getPriority());
}
private function buildConstraintViolation()
{
return $this->getMockBuilder('Symfony\Component\Validator\ConstraintViolation')
->disableOriginalConstructor()
->getMock();
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Ddeboer\DataImport\Tests\Step;
use Ddeboer\DataImport\Step\ValueConverterStep;
class ValueConverterStepTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
$this->filter = new ValueConverterStep();
}
public function testProcess()
{
$this->filter->add('[foo]', function($v) { return 'barfoo'; });
$data = ['foo' => 'foobar'];
$this->filter->process($data);
$this->assertEquals(['foo' => 'barfoo'], $data);
}
}