Skip to content

Commit

Permalink
Merge pull request #586 from extcode/task/cleanup_test
Browse files Browse the repository at this point in the history
[Task] Cleanup tests
  • Loading branch information
extcode authored Oct 16, 2024
2 parents 56fe34c + a9d9805 commit f6853a4
Show file tree
Hide file tree
Showing 29 changed files with 559 additions and 1,428 deletions.
2 changes: 1 addition & 1 deletion Classes/Controller/Cart/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class OrderController extends ActionController
{
protected function getErrorFlashMessage(): bool|string
protected function getErrorFlashMessage(): ?string
{
return LocalizationUtility::translate(
'tx_cart.error.validation',
Expand Down
7 changes: 4 additions & 3 deletions Tests/Unit/ConstantsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
namespace Extcode\Cart\Tests\Unit;

use Extcode\Cart\Constants;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

#[CoversClass(Constants::class)]
class ConstantsTest extends UnitTestCase
{
/**
* @test
*/
#[Test]
public function constantForDoktypeOfCartIsSetCorrectly(): void
{
self::assertEquals(181, Constants::DOKTYPE_CART_CART);
Expand Down
111 changes: 30 additions & 81 deletions Tests/Unit/Domain/Model/Cart/BeVariantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
use Extcode\Cart\Domain\Model\Cart\BeVariant;
use Extcode\Cart\Domain\Model\Cart\Product;
use Extcode\Cart\Domain\Model\Cart\TaxClass;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

#[CoversClass(BeVariant::class)]
class BeVariantTest extends UnitTestCase
{
protected TaxClass $taxClass;
Expand Down Expand Up @@ -78,9 +81,7 @@ public function setUp(): void
parent::setUp();
}

/**
* @test
*/
#[Test]
public function getIdReturnsIdSetByConstructor(): void
{
self::assertSame(
Expand All @@ -89,9 +90,7 @@ public function getIdReturnsIdSetByConstructor(): void
);
}

/**
* @test
*/
#[Test]
public function getSkuReturnsSkuSetByConstructor(): void
{
self::assertSame(
Expand All @@ -100,9 +99,7 @@ public function getSkuReturnsSkuSetByConstructor(): void
);
}

/**
* @test
*/
#[Test]
public function getCompleteSkuReturnsCompleteSkuSetByConstructor(): void
{
$sku = $this->product->getSku() . '-' . $this->sku;
Expand All @@ -112,9 +109,7 @@ public function getCompleteSkuReturnsCompleteSkuSetByConstructor(): void
);
}

/**
* @test
*/
#[Test]
public function getSkuWithSkuDelimiterReturnsSkuSetByConstructorWithGivenSkuDelimiter(): void
{
$skuDelimiter = '_';
Expand All @@ -127,9 +122,7 @@ public function getSkuWithSkuDelimiterReturnsSkuSetByConstructorWithGivenSkuDeli
);
}

/**
* @test
*/
#[Test]
public function getTitleReturnsTitleSetByConstructor(): void
{
self::assertSame(
Expand All @@ -138,9 +131,7 @@ public function getTitleReturnsTitleSetByConstructor(): void
);
}

/**
* @test
*/
#[Test]
public function getCompleteTitleReturnsCompleteTitleSetByConstructor(): void
{
$title = $this->product->getTitle() . ' - ' . $this->title;
Expand All @@ -150,9 +141,7 @@ public function getCompleteTitleReturnsCompleteTitleSetByConstructor(): void
);
}

/**
* @test
*/
#[Test]
public function getTitleWithTitleDelimiterReturnsTitleSetByConstructorWithGivenTitleDelimiter(): void
{
$titleDelimiter = ',';
Expand All @@ -165,9 +154,7 @@ public function getTitleWithTitleDelimiterReturnsTitleSetByConstructorWithGivenT
);
}

/**
* @test
*/
#[Test]
public function getPriceReturnsPriceSetByConstructor(): void
{
self::assertSame(
Expand All @@ -176,9 +163,7 @@ public function getPriceReturnsPriceSetByConstructor(): void
);
}

/**
* @test
*/
#[Test]
public function getPriceCalcMethodReturnsPriceCalcSetByConstructor(): void
{
self::assertSame(
Expand All @@ -187,9 +172,7 @@ public function getPriceCalcMethodReturnsPriceCalcSetByConstructor(): void
);
}

/**
* @test
*/
#[Test]
public function getQuantityReturnsQuantitySetByConstructor(): void
{
self::assertSame(
Expand All @@ -198,9 +181,7 @@ public function getQuantityReturnsQuantitySetByConstructor(): void
);
}

/**
* @test
*/
#[Test]
public function constructVariantWithoutCartProductOrVariantThrowsInvalidArgumentException(): void
{
$this->expectException(\InvalidArgumentException::class);
Expand All @@ -217,9 +198,7 @@ public function constructVariantWithoutCartProductOrVariantThrowsInvalidArgument
);
}

/**
* @test
*/
#[Test]
public function constructVariantWithCartProductAndVariantThrowsInvalidArgumentException(): void
{
$this->expectException(\InvalidArgumentException::class);
Expand All @@ -236,9 +215,7 @@ public function constructVariantWithCartProductAndVariantThrowsInvalidArgumentEx
);
}

/**
* @test
*/
#[Test]
public function constructWithoutTitleThrowsException(): void
{
$this->expectException(\TypeError::class);
Expand All @@ -255,9 +232,7 @@ public function constructWithoutTitleThrowsException(): void
);
}

/**
* @test
*/
#[Test]
public function constructWithoutSkuThrowsException(): void
{
$this->expectException(\TypeError::class);
Expand All @@ -274,9 +249,7 @@ public function constructWithoutSkuThrowsException(): void
);
}

/**
* @test
*/
#[Test]
public function constructWithoutQuantityThrowsException(): void
{
$this->expectException(\TypeError::class);
Expand All @@ -293,9 +266,7 @@ public function constructWithoutQuantityThrowsException(): void
);
}

/**
* @test
*/
#[Test]
public function getMinReturnsInitialValueMin(): void
{
self::assertSame(
Expand All @@ -304,9 +275,7 @@ public function getMinReturnsInitialValueMin(): void
);
}

/**
* @test
*/
#[Test]
public function setMinIfMinIsEqualToMax(): void
{
$min = 1;
Expand All @@ -321,9 +290,7 @@ public function setMinIfMinIsEqualToMax(): void
);
}

/**
* @test
*/
#[Test]
public function setMinIfMinIsLesserThanMax(): void
{
$min = 1;
Expand All @@ -338,9 +305,7 @@ public function setMinIfMinIsLesserThanMax(): void
);
}

/**
* @test
*/
#[Test]
public function throwsInvalidArgumentExceptionIfMinIsGreaterThanMax(): void
{
$this->expectException(\InvalidArgumentException::class);
Expand All @@ -352,9 +317,7 @@ public function throwsInvalidArgumentExceptionIfMinIsGreaterThanMax(): void
$this->beVariant->setMin($min);
}

/**
* @test
*/
#[Test]
public function throwsInvalidArgumentExceptionIfMinIsNegativ(): void
{
$this->expectException(\InvalidArgumentException::class);
Expand All @@ -366,9 +329,7 @@ public function throwsInvalidArgumentExceptionIfMinIsNegativ(): void
$this->beVariant->setMin($min);
}

/**
* @test
*/
#[Test]
public function getMaxReturnsInitialValueMax(): void
{
self::assertSame(
Expand All @@ -377,9 +338,7 @@ public function getMaxReturnsInitialValueMax(): void
);
}

/**
* @test
*/
#[Test]
public function setMaxIfMaxIsEqualToMin(): void
{
$min = 1;
Expand All @@ -397,9 +356,7 @@ public function setMaxIfMaxIsEqualToMin(): void
);
}

/**
* @test
*/
#[Test]
public function setMaxIfMaxIsGreaterThanMin(): void
{
$min = 1;
Expand All @@ -417,9 +374,7 @@ public function setMaxIfMaxIsGreaterThanMin(): void
);
}

/**
* @test
*/
#[Test]
public function throwsInvalidArgumentExceptionIfMaxIsLesserThanMin(): void
{
$this->expectException(\InvalidArgumentException::class);
Expand All @@ -434,9 +389,7 @@ public function throwsInvalidArgumentExceptionIfMaxIsLesserThanMin(): void
$this->beVariant->setMax($max);
}

/**
* @test
*/
#[Test]
public function getParentPriceReturnsProductPriceForCalculationMethodZero(): void
{
self::assertSame(
Expand All @@ -445,9 +398,7 @@ public function getParentPriceReturnsProductPriceForCalculationMethodZero(): voi
);
}

/**
* @test
*/
#[Test]
public function getParentPriceReturnsZeroPriceForCalculationMethodOne(): void
{
$this->beVariant->setPriceCalcMethod(1);
Expand All @@ -457,9 +408,7 @@ public function getParentPriceReturnsZeroPriceForCalculationMethodOne(): void
);
}

/**
* @test
*/
#[Test]
public function getParentPriceRespectsTheQuantityDiscountsOfProductsForEachVariant(): void
{
$quantityDiscounts = [
Expand Down
Loading

0 comments on commit f6853a4

Please sign in to comment.