2021-08-18 13:54:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import;
|
|
|
|
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Import;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportLog;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportLogEntry;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \WerkraumMedia\ThueCat\Domain\Import\Import
|
|
|
|
*/
|
|
|
|
class ImportTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function canBeCreated(): void
|
|
|
|
{
|
|
|
|
$subject = new Import();
|
|
|
|
|
|
|
|
self::assertInstanceOf(
|
|
|
|
Import::class,
|
|
|
|
$subject
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function canStart(): void
|
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration = new ImportConfiguration();
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject = new Import();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->start($configuration);
|
2021-08-18 13:54:18 +02:00
|
|
|
|
|
|
|
self::assertSame(
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration,
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject->getConfiguration()
|
|
|
|
);
|
|
|
|
self::assertInstanceOf(
|
|
|
|
ImportLog::class,
|
|
|
|
$subject->getLog()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function canEndAfterStart(): void
|
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration = new ImportConfiguration();
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject = new Import();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->start($configuration);
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject->end();
|
|
|
|
|
|
|
|
self::assertSame(
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration,
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject->getConfiguration()
|
|
|
|
);
|
|
|
|
self::assertInstanceOf(
|
|
|
|
ImportLog::class,
|
|
|
|
$subject->getLog()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function isDoneAfterStartAndEnd(): void
|
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration = new ImportConfiguration();
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject = new Import();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->start($configuration);
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject->end();
|
|
|
|
|
|
|
|
self::assertTrue($subject->done());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function isNotDoneAfterJustStartWithoutEnd(): void
|
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration = new ImportConfiguration();
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject = new Import();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->start($configuration);
|
2021-08-18 13:54:18 +02:00
|
|
|
|
|
|
|
self::assertFalse($subject->done());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function nestedStartReturnsExpectedConfiguration(): void
|
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration1 = new ImportConfiguration();
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject = new Import();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->start($configuration1);
|
2021-08-18 13:54:18 +02:00
|
|
|
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration2 = new ImportConfiguration();
|
|
|
|
$subject->start($configuration2);
|
2021-08-18 13:54:18 +02:00
|
|
|
|
|
|
|
self::assertSame(
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration2,
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject->getConfiguration()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function nestedStartReturnsExpectedLog(): void
|
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration1 = new ImportConfiguration();
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject = new Import();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->start($configuration1);
|
2021-08-18 13:54:18 +02:00
|
|
|
|
|
|
|
$log1 = $subject->getLog();
|
|
|
|
self::assertInstanceOf(
|
|
|
|
ImportLog::class,
|
|
|
|
$log1
|
|
|
|
);
|
|
|
|
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration2 = new ImportConfiguration();
|
|
|
|
$subject->start($configuration2);
|
2021-08-18 13:54:18 +02:00
|
|
|
|
|
|
|
$log2 = $subject->getLog();
|
|
|
|
self::assertInstanceOf(
|
|
|
|
ImportLog::class,
|
|
|
|
$log2
|
|
|
|
);
|
|
|
|
|
|
|
|
self::assertNotSame(
|
|
|
|
$log1,
|
|
|
|
$log2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function nestedImportMergesLog(): void
|
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration1 = new ImportConfiguration();
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject = new Import();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->start($configuration1);
|
2021-08-18 13:54:18 +02:00
|
|
|
|
|
|
|
$log1 = $subject->getLog();
|
|
|
|
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration2 = new ImportConfiguration();
|
|
|
|
$subject->start($configuration2);
|
|
|
|
$importLogEntry = $this->createStub(ImportLogEntry::class);
|
|
|
|
$subject->getLog()->addEntry($importLogEntry);
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject->end();
|
|
|
|
|
|
|
|
self::assertSame(
|
|
|
|
$log1,
|
|
|
|
$subject->getLog()
|
|
|
|
);
|
|
|
|
|
|
|
|
self::assertSame(
|
|
|
|
[
|
2022-09-13 09:05:47 +02:00
|
|
|
$importLogEntry
|
2021-08-18 13:54:18 +02:00
|
|
|
],
|
|
|
|
$log1->getEntries()->toArray()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function nestedImportReturnsHandledForRemoteId(): void
|
|
|
|
{
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration1 = new ImportConfiguration();
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject = new Import();
|
2022-09-13 09:05:47 +02:00
|
|
|
$subject->start($configuration1);
|
2021-08-18 13:54:18 +02:00
|
|
|
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration2 = new ImportConfiguration();
|
|
|
|
$subject->start($configuration2);
|
|
|
|
$importLogEntry = $this->createStub(ImportLogEntry::class);
|
|
|
|
$importLogEntry->method('getRemoteId')->willReturn('https://example.com/remote-id');
|
|
|
|
$subject->getLog()->addEntry($importLogEntry);
|
2021-08-18 13:54:18 +02:00
|
|
|
$subject->end();
|
|
|
|
|
2022-09-13 09:05:47 +02:00
|
|
|
$configuration3 = new ImportConfiguration();
|
|
|
|
$subject->start($configuration3);
|
2021-08-18 13:54:18 +02:00
|
|
|
self::assertTrue(
|
|
|
|
$subject->handledRemoteId('https://example.com/remote-id')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|