Skip to content

Commit

Permalink
Merge pull request #16 from dikastes/13-test-publisheditems-getcompos…
Browse files Browse the repository at this point in the history
…ers-function

13 test publisheditems getcomposers function
  • Loading branch information
dikastes authored Mar 4, 2024
2 parents 88107aa + dd2b02e commit 11f1dbe
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 10 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,49 @@ jobs:
run: "composer update --no-progress"
- name: "Run the tests"
run: "composer ci:tests:unit"

functional-tests:
name: Functional Tests
runs-on: ubuntu-22.04
needs: [ code-quality ]
strategy:
matrix:
php-version:
- '8.2'
- '8.3'
env:
DB_DATABASE: typo3
DB_USER: root
DB_PASSWORD: root
DB_HOST: 127.0.0.1

steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Install PHP"
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-version }}"
coverage: none
tools: composer:v2.6
- name: "Show Composer version"
run: composer --version
- name: "Show the Composer configuration"
run: composer config --global --list
- name: "Cache dependencies installed with composer"
uses: actions/cache@v4
with:
key: "php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}"
path: ~/.cache/composer
restore-keys: "php${{ matrix.php-version }}-composer-\n"
- name: "Install Composer dependencies"
run: "composer update --no-progress"
- name: "Start MySQL"
run: "sudo /etc/init.d/mysql start"
- name: "Run the tests"
run: |
export typo3DatabaseName="$DB_DATABASE";
export typo3DatabaseHost="$DB_HOST";
export typo3DatabaseUsername="$DB_USER";
export typo3DatabasePassword="$DB_PASSWORD";
composer ci:tests:functional
2 changes: 1 addition & 1 deletion Classes/Domain/Model/PublishedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ public function getComposers(): string
return Collection::wrap($this->containedWorks->toArray())->
map( function($work) { return self::getWorkComposerName($work); } )->
unique()->
join(';');
join('; ');
}

protected static function getComposerName(GndPerson $composer): string
Expand Down
141 changes: 141 additions & 0 deletions Tests/Functional/Domain/Model/PublishedItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php
namespace Slub\MpdbCore\Tests\Unit\Domain\Model;

use Slub\DmNorm\Domain\Model\GndPerson;
use Slub\DmNorm\Domain\Model\GndWork;
use Slub\MpdbCore\Domain\Model\PublishedItem;
use Slub\MpdbCore\Domain\Model\PublishedSubitem;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

/**
* Test case.
*
* @author Matthias Richter <[email protected]>
*/
class PublishedItemTest extends FunctionalTestCase
{
/**
* @var \Slub\PublisherDb\Domain\Model\PublishedItem
*/
protected ?PublishedItem $subject = null;

/**
* @var \Slub\DmNorm\Domain\Model\GndPerson
*/
protected ?GndPerson $composer1 = null;

/**
* @var \Slub\DmNorm\Domain\Model\GndPerson
*/
protected ?GndPerson $composer2 = null;

/**
* @var \Slub\DmNorm\Domain\Model\GndWork
*/
protected ?GndWork $work1 = null;

/**
* @var \Slub\DmNorm\Domain\Model\GndWork
*/
protected ?GndWork $work2 = null;

/**
* @var string
*/
protected string $nameComposer1 = 'Composer 1';

/**
* @var string
*/
protected string $nameComposer2 = 'Composer 2';

protected function setUp(): void
{
parent::setUp();
$this->subject = new PublishedItem();

$this->composer1 = new GndPerson();
$this->composer2 = new GndPerson();
$this->composer1->setName($this->nameComposer1);
$this->composer2->setName($this->nameComposer2);

$this->work1 = new GndWork();
$this->work2 = new GndWork();
$this->work1->setFirstComposer($this->composer1);
$this->work2->setFirstComposer($this->composer2);
}

protected function tearDown(): void
{
parent::tearDown();
}

/**
* @test
*/
public function publishedItemWithOneComposerReturnsComposer()
{
$this->subject->addFirstComposer($this->composer1);

self::assertSame(
$this->nameComposer1,
$this->subject->getComposers()
);
}

/**
* @test
*/
public function publishedItemWithManyComposersReturnsComposers()
{
$this->subject->addFirstComposer($this->composer1);
$this->subject->addFirstComposer($this->composer2);
$namesString = implode('; ', [$this->nameComposer1, $this->nameComposer2]);

self::assertSame(
$namesString,
$this->subject->getComposers()
);
}

/**
* @test
*/
public function publishedItemWithoutComposersReturnsOneWorkComposer()
{
$this->subject->addContainedWork($this->work1);

self::assertSame(
$this->nameComposer1,
$this->subject->getComposers()
);
}

/**
* @test
*/
public function publishedItemWithoutComposerReturnsManyWorkComposers()
{
$this->subject->addContainedWork($this->work1);
$this->subject->addContainedWork($this->work2);
$namesString = implode('; ', [$this->nameComposer1, $this->nameComposer2]);

self::assertSame(
$namesString,
$this->subject->getComposers()
);
}

/**
* @test
*/
public function publishedItemWithoutComposerWithoutWorkcomposersReturnsString()
{
self::assertSame(
'',
$this->subject->getComposers()
);
}

}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
"ci": [ "@ci:php", "@ci:tests" ],
"ci:php": [ "@ci:php:stan" ],
"ci:php:stan": [ "phpstan analyse Classes" ],
"ci:tests": [ "@ci:tests:unit" ],
"ci:tests:unit": [ "phpunit -c config/UnitTests.xml" ]
"ci:tests": [ "@ci:tests:unit", "@ci:tests:functional" ],
"ci:tests:unit": [ "phpunit -c config/UnitTests.xml" ],
"ci:tests:functional": [ "phpunit -c config/FunctionalTests.xml" ]
},
"extra": {
"typo3/cms": {
Expand Down
29 changes: 29 additions & 0 deletions config/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="../.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php"
cacheResult="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<testsuites>
<testsuite name="MpdbCore">
<directory>../Tests/Functional</directory>
</testsuite>
</testsuites>

<php>
<!--
@deprecated: Set this to not suppress warnings, notices and deprecations in functional tests
with TYPO3 core v11 and up.
Will always be done with next major version.
To still suppress warnings, notices and deprecations, do NOT define the constant at all.
-->
<const name="TYPO3_TESTING_FUNCTIONAL_REMOVE_ERROR_HANDLER" value="true"/>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
7 changes: 0 additions & 7 deletions config/UnitTests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@
colors="true"
failOnRisky="true"
failOnWarning="true"
requireCoverageMetadata="true"
>
<testsuites>
<testsuite name="MpdbCore">
<directory>../Tests/Unit</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory>../Classes</directory>
</include>
</source>

<php>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
Expand Down

0 comments on commit 11f1dbe

Please sign in to comment.