Skip to content

Commit

Permalink
Add Attributes for Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ipf committed Jan 6, 2025
1 parent 71853f0 commit 9b50292
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 84 deletions.
9 changes: 4 additions & 5 deletions Tests/Unit/Controller/SearchControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\Attributes\Test;
use Subugoe\Find\Controller\SearchController;
use TYPO3\TestingFramework\Core\BaseTestCase;

Expand All @@ -47,11 +49,8 @@ protected function setUp(): void
->getMock();
}

/**
* @test
*
* @doesNotPerformAssertions
*/
#[Test]
#[DoesNotPerformAssertions]
public function implementTests(): void
{
self::markTestIncomplete();
Expand Down
14 changes: 4 additions & 10 deletions Tests/Unit/Service/SolrServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use PHPUnit\Framework\Attributes\Test;
use Subugoe\Find\Service\SolrServiceProvider;
use TYPO3\TestingFramework\Core\BaseTestCase;

Expand All @@ -42,15 +43,10 @@ class SolrServiceProviderTest extends BaseTestCase

protected function setUp(): void
{
$this->fixture = $this->getMockBuilder(SolrServiceProvider::class)
->addMethods(['dummy'])
->disableOriginalConstructor()
->getMock();
$this->fixture = $this->getAccessibleMock(SolrServiceProvider::class, null, callOriginalConstructor: false);
}

/**
* @test
*/
#[Test]
public function setConfigurationAddsTheValueToConfigurationArray()
{
$key = 'foo';
Expand All @@ -60,9 +56,7 @@ public function setConfigurationAddsTheValueToConfigurationArray()
self::assertArrayHasKey($key, $this->fixture->getConfiguration());
}

/**
* @test
*/
#[Test]
public function setConfigurationAddsAKeyValuePairToAnExistingConfiguration()
{
$key = 'foo';
Expand Down
11 changes: 5 additions & 6 deletions Tests/Unit/Utility/UpgradeUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace Subugoe\Find\Tests\Unit\Utility;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Subugoe\Find\Utility\UpgradeUtility;
use TYPO3\TestingFramework\Core\BaseTestCase;

class UpgradeUtilityTest extends BaseTestCase
{
public function settingsProvider(): array
public static function settingsProvider(): array
{
return [
[
Expand Down Expand Up @@ -61,11 +63,8 @@ public function settingsProvider(): array
];
}

/**
* @test
*
* @dataProvider settingsProvider
*/
#[DataProvider('settingsProvider')]
#[Test]
public function configurationIsAutomaticallyUpgraded(array $settings, $expected): void
{
self::assertSame($expected, UpgradeUtility::handleSolariumUpgrade($settings));
Expand Down
17 changes: 5 additions & 12 deletions Tests/Unit/ViewHelpers/Data/NewArrayViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use Subugoe\Find\ViewHelpers\Data\NewArrayViewHelper;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
Expand All @@ -48,9 +49,7 @@ protected function setUp(): void
$this->fixture->setRenderingContext($this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock());
}

/**
* @test
*/
#[Test]
public function aNewArrayFromArgumentsIsCorrectlyCreated(): void
{
$arguments = [
Expand All @@ -70,9 +69,7 @@ public function aNewArrayFromArgumentsIsCorrectlyCreated(): void
self::assertSame($expected, $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function aNewArrayWithoutAnExistingOneIsCreated(): void
{
$arguments = [
Expand All @@ -90,9 +87,7 @@ public function aNewArrayWithoutAnExistingOneIsCreated(): void
self::assertSame($expected, $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function aNewArrayWithMultipleEntriesIsCreated(): void
{
$arguments = [
Expand All @@ -111,9 +106,7 @@ public function aNewArrayWithMultipleEntriesIsCreated(): void
self::assertSame($expected, $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function emptyStringsAsArrayKeysAreConsideredAsKeysAndValues(): void
{
$arguments = [
Expand Down
17 changes: 5 additions & 12 deletions Tests/Unit/ViewHelpers/Data/SplitViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use PHPUnit\Framework\Attributes\Test;
use Subugoe\Find\ViewHelpers\Data\SplitViewHelper;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
use TYPO3\TestingFramework\Core\BaseTestCase;
Expand All @@ -48,9 +49,7 @@ protected function setUp(): void
$this->fixture->setRenderingContext($this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock());
}

/**
* @test
*/
#[Test]
public function stringIsExplodedCorrectlyWithoutPassedSeparator()
{
$string = 'hrdr, behedeti, horus';
Expand All @@ -64,9 +63,7 @@ public function stringIsExplodedCorrectlyWithoutPassedSeparator()
self::assertSame($expected, $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function stringIsExplodedCorrectlyWithPassedSeparator()
{
$string = 'hrdr, behedeti, horus';
Expand All @@ -81,9 +78,7 @@ public function stringIsExplodedCorrectlyWithPassedSeparator()
self::assertSame($expected, $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function stringIsExplodedCorrectlyWithNonDefaultSeparator()
{
$string = 'hrdrhorus behedetihorus horus';
Expand All @@ -97,9 +92,7 @@ public function stringIsExplodedCorrectlyWithNonDefaultSeparator()
self::assertSame($expected, $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function emptyArrayIsReturnedWhenPassingIt()
{
$string = '';
Expand Down
17 changes: 5 additions & 12 deletions Tests/Unit/ViewHelpers/Data/ValueForKeyViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use PHPUnit\Framework\Attributes\Test;
use Subugoe\Find\Tests\Unit\ViewHelpers\MockRenderingContextTrait;
use Subugoe\Find\ViewHelpers\Data\ValueForKeyViewHelper;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
Expand All @@ -51,9 +52,7 @@ protected function setUp(): void
$this->fixture->setRenderingContext($this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock());
}

/**
* @test
*/
#[Test]
public function keyPicksTheRightValueFromTheArray()
{
$array = [
Expand All @@ -70,9 +69,7 @@ public function keyPicksTheRightValueFromTheArray()
self::assertSame('b', $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function resultIsCorrectlyInterpretedAsJsonFromASimpleValue()
{
$array = [
Expand All @@ -90,9 +87,7 @@ public function resultIsCorrectlyInterpretedAsJsonFromASimpleValue()
self::assertSame('b', $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function resultIsCorrectlyInterpretedAsTextFromASimpleValue()
{
$array = [
Expand All @@ -110,9 +105,7 @@ public function resultIsCorrectlyInterpretedAsTextFromASimpleValue()
self::assertSame('b', $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function providingANonexistingKeyReturnsNull()
{
$array = [
Expand Down
9 changes: 3 additions & 6 deletions Tests/Unit/ViewHelpers/Find/FacetIsActiveViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use PHPUnit\Framework\Attributes\Test;
use Subugoe\Find\ViewHelpers\Find\FacetIsActiveViewHelper;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
use TYPO3\TestingFramework\Core\BaseTestCase;
Expand All @@ -47,9 +48,7 @@ protected function setUp(): void
$this->fixture->setRenderingContext($this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock());
}

/**
* @test
*/
#[Test]
public function activeFacetIsCorrectlyRecognized()
{
$arguments = [
Expand All @@ -75,9 +74,7 @@ public function activeFacetIsCorrectlyRecognized()
self::assertTrue($this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function notActiveFacetsReturnFalse()
{
$arguments = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use PHPUnit\Framework\Attributes\Test;
use Subugoe\Find\Tests\Unit\ViewHelpers\MockRenderingContextTrait;
use Subugoe\Find\ViewHelpers\Find\FacetLinkArgumentsViewHelper;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
Expand All @@ -50,9 +51,7 @@ protected function setUp(): void
$this->fixture->setRenderingContext($this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock());
}

/**
* @test
*/
#[Test]
public function filterIsCorrectlyRemovedOnTextQueries()
{
$this->fixture->setArguments([
Expand All @@ -66,9 +65,7 @@ public function filterIsCorrectlyRemovedOnTextQueries()
self::assertEquals('tx_find_find[facet][title]', $result[0]);
}

/**
* @test
*/
#[Test]
public function filterIsCorrectlyAddedOnTextQueries()
{
$this->fixture->setArguments([
Expand Down
9 changes: 4 additions & 5 deletions Tests/Unit/ViewHelpers/Find/HighlightFieldViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\Attributes\Test;
use Subugoe\Find\ViewHelpers\Find\HighlightFieldViewHelper;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
use TYPO3\TestingFramework\Core\BaseTestCase;
Expand All @@ -52,11 +54,8 @@ protected function setUp(): void
$this->fixture->setRenderingContext($this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock());
}

/**
* @test
*
* @doesNotPerformAssertions
*/
#[Test]
#[DoesNotPerformAssertions]
public function fieldIsCorrectlyHighlighted()
{
self::markTestIncomplete('Still something to do with mocking solarium');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use PHPUnit\Framework\Attributes\Test;
use Subugoe\Find\Tests\Unit\ViewHelpers\MockRenderingContextTrait;
use Subugoe\Find\ViewHelpers\Find\PageNumberForResultNumberViewHelper;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
Expand All @@ -51,9 +52,7 @@ protected function setUp(): void
$this->fixture->setRenderingContext($this->getMockBuilder(RenderingContext::class)->disableOriginalConstructor()->getMock());
}

/**
* @test
*/
#[Test]
public function pageNumberIsCorrectlyCalculated()
{
$resultNumber = 55;
Expand All @@ -68,9 +67,7 @@ public function pageNumberIsCorrectlyCalculated()
self::assertSame($expected, $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function pageNumerWhenResultIsZero()
{
$resultNumber = 0;
Expand All @@ -86,9 +83,7 @@ public function pageNumerWhenResultIsZero()
self::assertSame($expected, $this->fixture->initializeArgumentsAndRender());
}

/**
* @test
*/
#[Test]
public function divisionByZeroIsCaught()
{
$resultNumber = 0;
Expand All @@ -103,7 +98,8 @@ public function divisionByZeroIsCaught()
self::assertSame($expected, $this->fixture->initializeArgumentsAndRender());
}

public function pageNumberFallBackForZeroResultsPerPage()
#[Test]
public function pageNumberFallBackForZeroResultsPerPage(): void
{
$resultNumber = 55;
$resultsPerPage = 0;
Expand Down

0 comments on commit 9b50292

Please sign in to comment.