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,28 @@
<?php
namespace spec\Ddeboer\DataImport\Exception;
use PhpSpec\ObjectBehavior;
class DuplicateHeadersExceptionSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(['header1', 'header2']);
}
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Exception\DuplicateHeadersException');
}
function it_is_a_reader_exception()
{
$this->shouldHaveType('Ddeboer\DataImport\Exception\ReaderException');
}
function it_has_a_message()
{
$this->getMessage()->shouldReturn('File contains duplicate headers: header1, header2');
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace spec\Ddeboer\DataImport\Exception;
use PhpSpec\ObjectBehavior;
class MappingExceptionSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Exception\MappingException');
}
function it_is_an_exception()
{
$this->shouldHaveType('Exception');
$this->shouldImplement('Ddeboer\DataImport\Exception');
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace spec\Ddeboer\DataImport\Exception;
use PhpSpec\ObjectBehavior;
class ReaderExceptionSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Exception\ReaderException');
}
function it_is_an_exception()
{
$this->shouldHaveType('Exception');
$this->shouldImplement('Ddeboer\DataImport\Exception');
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace spec\Ddeboer\DataImport\Exception;
use PhpSpec\ObjectBehavior;
class SourceNotFoundExceptionSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Exception\SourceNotFoundException');
}
function it_is_an_exception()
{
$this->shouldHaveType('Exception');
$this->shouldImplement('Ddeboer\DataImport\Exception');
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace spec\Ddeboer\DataImport\Exception;
use PhpSpec\ObjectBehavior;
class UnexpectedTypeExceptionSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith(123, 'string');
}
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Exception\UnexpectedTypeException');
}
function it_is_an_unexpected_value_exception()
{
$this->shouldHaveType('Ddeboer\DataImport\Exception\UnexpectedValueException');
}
function it_has_a_message_with_scalar_type()
{
$this->getMessage()->shouldReturn('Expected argument of type "string", "integer" given');
}
function it_has_a_message_with_object_type()
{
$this->beConstructedWith(new \stdClass, 'string');
$this->getMessage()->shouldReturn('Expected argument of type "string", "stdClass" given');
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace spec\Ddeboer\DataImport\Exception;
use PhpSpec\ObjectBehavior;
class UnexpectedValueExceptionSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Exception\UnexpectedValueException');
}
function it_is_an_exception()
{
$this->shouldImplement('Ddeboer\DataImport\Exception');
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace spec\Ddeboer\DataImport\Exception;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Validator\ConstraintViolationListInterface;
class ValidationExceptionSpec extends ObjectBehavior
{
function let(ConstraintViolationListInterface $list)
{
$this->beConstructedWith($list, 1);
}
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Exception\ValidationException');
}
function it_is_an_exception()
{
$this->shouldHaveType('Exception');
$this->shouldImplement('Ddeboer\DataImport\Exception');
}
function it_has_a_list_of_violations(ConstraintViolationListInterface $list)
{
$this->getViolations()->shouldReturn($list);
}
function it_has_a_line_number()
{
$this->getLineNumber()->shouldReturn(1);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace spec\Ddeboer\DataImport\Exception;
use PhpSpec\ObjectBehavior;
class WriterExceptionSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Exception\WriterException');
}
function it_is_an_exception()
{
$this->shouldHaveType('Exception');
$this->shouldImplement('Ddeboer\DataImport\Exception');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace spec\Ddeboer\DataImport\Filter;
use Ddeboer\DataImport\ValueConverter\DateTimeValueConverter;
use PhpSpec\ObjectBehavior;
class DateTimeThresholdFilterSpec extends ObjectBehavior
{
function let(DateTimeValueConverter $valueConverter)
{
$this->beConstructedWith($valueConverter);
}
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Filter\DateTimeThresholdFilter');
}
function it_throws_an_exception_when_no_threshold_is_set()
{
$this->shouldThrow('LogicException')->during__invoke([]);
}
function it_accepts_a_threshold(\DateTime $dateTime)
{
$this->setThreshold($dateTime);
}
function it_filters_an_item_based_on_a_time_column(DateTimeValueConverter $valueConverter)
{
$item = [
'updated_at' => '1970-01-01'
];
$valueConverter->__invoke($item['updated_at'])->willReturn(new \DateTime('1970-01-01'));
$this->beConstructedWith($valueConverter, new \DateTime());
$this->__invoke($item)->shouldReturn(false);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace spec\Ddeboer\DataImport\Filter;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class OffsetFilterSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Filter\OffsetFilter');
}
function it_does_not_limit_by_default()
{
$this->__invoke(['content'])->shouldReturn(true);
}
function it_limits_until_the_start_offset()
{
$this->beConstructedWith(1);
$this->__invoke(['content'])->shouldReturn(false);
$this->__invoke(['content'])->shouldReturn(true);
}
function it_limits_when_max_is_reached()
{
$this->beConstructedWith(0, 2);
$this->__invoke(['content'])->shouldReturn(true);
$this->__invoke(['content'])->shouldReturn(true);
$this->__invoke(['content'])->shouldReturn(false);
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace spec\Ddeboer\DataImport\Filter;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ValidatorFilterSpec extends ObjectBehavior
{
/**
* @var array
*/
protected $item1 = ['key1' => 'value1'];
/**
* @var array
*/
protected $item2 = [
'key1' => 'value1',
'key2' => 'value2'
];
function let(ValidatorInterface $validator)
{
$this->beConstructedWith($validator);
}
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Filter\ValidatorFilter');
}
function it_validates_an_item(ValidatorInterface $validator, Constraint $constraint, ConstraintViolationList $list)
{
$list->count()->willReturn(0);
$validator->validate($this->item1, Argument::type('Symfony\Component\Validator\Constraints\Collection'))->willReturn($list);
$this->add('key1', $constraint);
$this->__invoke($this->item1);
}
function it_validates_an_item_non_strictly(ValidatorInterface $validator, Constraint $constraint, ConstraintViolationList $list)
{
$list->count()->willReturn(0);
$validator->validate($this->item1, Argument::type('Symfony\Component\Validator\Constraints\Collection'))->willReturn($list);
$this->setStrict(false);
$this->add('key1', $constraint);
$this->__invoke($this->item1);
$this->__invoke($this->item2);
}
function it_validates_an_item_and_the_validation_fails(ValidatorInterface $validator, Constraint $constraint, ConstraintViolationList $list)
{
$list->count()->willReturn(1);
$validator->validate($this->item1, Argument::type('Symfony\Component\Validator\Constraints\Collection'))->willReturn($list);
$this->add('key1', $constraint);
$this->__invoke($this->item1);
$this->getViolations()->shouldReturn([1 => $list]);
}
function it_validates_an_item_and_the_validation_fails_with_exception(ValidatorInterface $validator, Constraint $constraint, ConstraintViolationList $list)
{
$list->count()->willReturn(1);
$validator->validate($this->item1, Argument::type('Symfony\Component\Validator\Constraints\Collection'))->willReturn($list);
$this->throwExceptions(true);
$this->add('key1', $constraint);
$this->shouldThrow('Ddeboer\DataImport\Exception\ValidationException')->during__invoke($this->item1);
$this->getViolations()->shouldReturn([1 => $list]);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace spec\Ddeboer\DataImport\Reader\Factory;
use PhpSpec\ObjectBehavior;
class CsvReaderFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Reader\Factory\CsvReaderFactory');
}
function it_creates_a_reader()
{
$file = new \SplFileObject(tempnam(sys_get_temp_dir(), null));
$this->getReader($file)->shouldHaveType('Ddeboer\DataImport\Reader\CsvReader');
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace spec\Ddeboer\DataImport\Reader\Factory;
use Doctrine\DBAL\Connection;
use PhpSpec\ObjectBehavior;
class DbalReaderFactorySpec extends ObjectBehavior
{
function let(Connection $dbal)
{
$this->beConstructedWith($dbal);
}
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Reader\Factory\DbalReaderFactory');
}
function it_creates_a_reader()
{
$this->getReader('SQL', [])->shouldHaveType('Ddeboer\DataImport\Reader\DbalReader');
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace spec\Ddeboer\DataImport\Reader\Factory;
use Doctrine\Common\Persistence\ObjectManager;
use PhpSpec\ObjectBehavior;
class DoctrineReaderFactorySpec extends ObjectBehavior
{
function let(ObjectManager $objectManager)
{
$this->beConstructedWith($objectManager);
}
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Reader\Factory\DoctrineReaderFactory');
}
function it_creates_a_reader()
{
$this->getReader('Entity')->shouldHaveType('Ddeboer\DataImport\Reader\DoctrineReader');
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace spec\Ddeboer\DataImport\Reader\Factory;
use PhpSpec\ObjectBehavior;
class ExcelReaderFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Reader\Factory\ExcelReaderFactory');
}
function it_creates_a_reader()
{
$file = new \SplFileObject(tempnam(sys_get_temp_dir(), null));
$this->getReader($file)->shouldHaveType('Ddeboer\DataImport\Reader\ExcelReader');
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace spec\Ddeboer\DataImport;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ResultSpec extends ObjectBehavior
{
function let(\DateTime $startTime, \DateTime $endTime, \SplObjectStorage $exceptions, \DateInterval $elapsed)
{
$startTime->diff($endTime)->willReturn($elapsed);
$exceptions->count()->willReturn(4);
$this->beConstructedWith('name', $startTime, $endTime, 10, $exceptions);
}
function it_is_initializable()
{
$this->shouldHaveType('Ddeboer\DataImport\Result');
}
function it_has_a_name()
{
$this->getName()->shouldReturn('name');
}
function it_has_a_start_time(\DateTime $startTime)
{
$this->getStartTime()->shouldReturn($startTime);
}
function it_has_a_end_time(\DateTime $endTime)
{
$this->getEndTime()->shouldReturn($endTime);
}
function it_has_an_elapsed_time(\DateInterval $elapsed)
{
$this->getElapsed()->shouldReturn($elapsed);
}
function it_has_an_error_count()
{
$this->getErrorCount()->shouldReturn(4);
}
function it_has_a_success_count()
{
$this->getSuccessCount()->shouldReturn(6);
}
function it_has_a_total_processed_count()
{
$this->getTotalProcessedCount()->shouldReturn(10);
}
function it_checks_if_it_has_errors()
{
$this->hasErrors()->shouldReturn(true);
}
function it_has_exceptions(\SplObjectStorage $exceptions)
{
$this->getExceptions()->shouldReturn($exceptions);
}
}