-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9563d42
commit 728c516
Showing
15 changed files
with
846 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Controller; | ||
|
||
use App\Controller\AbstractController; | ||
use App\Report\HtmlReport; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\MockObject\Exception; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(HtmlReport::class)] | ||
class HtmlReportTest extends TestCase | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public function testRender(): void | ||
{ | ||
$html = <<<HTML | ||
<html> | ||
<body> | ||
<i>Test</i> | ||
<br> | ||
<div>Text</div>< | ||
</body> | ||
</html> | ||
HTML; | ||
$controller = $this->createMock(AbstractController::class); | ||
$report = new HtmlReport($controller, $html); | ||
$report->addPage(); | ||
$report->updateLeftMargin($report->getLeftMargin()); | ||
$report->updateRightMargin($report->getRightMargin()); | ||
$report->setLeftMargin(0.0); | ||
$report->setRightMargin(0.0); | ||
$report->addPage(); | ||
$report->setLeftMargin(20.0); | ||
$report->setRightMargin(20.0); | ||
$report->addPage(); | ||
$actual = $report->render(); | ||
|
||
self::assertTrue($actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function testRenderEmpty(): void | ||
{ | ||
$controller = $this->createMock(AbstractController::class); | ||
$report = new HtmlReport($controller, ''); | ||
$actual = $report->render(); | ||
self::assertFalse($actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function testRenderList(): void | ||
{ | ||
$html = <<<HTML | ||
<html> | ||
<body> | ||
<ul> | ||
<li>Milk</li> | ||
<li> | ||
Cheese | ||
<ul> | ||
<li>Blue cheese</li> | ||
<li>Feta</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
<ol> | ||
<li>Mix flour, baking powder, sugar, and salt.</li> | ||
<li>In another bowl, mix eggs, milk, and oil.</li> | ||
<li>Stir both mixtures together.</li> | ||
<li>Fill muffin tray 3/4 full.</li> | ||
<li>Bake for 20 minutes. | ||
<ol> | ||
<li>Stir both mixtures together.</li> | ||
<li>Fill muffin tray 3/4 full.</li> | ||
</ol> | ||
</li> | ||
</ol> | ||
</body> | ||
</html> | ||
HTML; | ||
|
||
$controller = $this->createMock(AbstractController::class); | ||
$report = new HtmlReport($controller, $html); | ||
$report->addPage(); | ||
$actual = $report->render(); | ||
self::assertTrue($actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function testRenderSpace(): void | ||
{ | ||
$controller = $this->createMock(AbstractController::class); | ||
$report = new HtmlReport($controller, ' '); | ||
$actual = $report->render(); | ||
self::assertFalse($actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Faker; | ||
|
||
use App\Entity\CalculationState; | ||
use App\Faker\CalculationStateProvider; | ||
use App\Faker\EntityProvider; | ||
use App\Faker\Factory; | ||
use App\Repository\UserRepository; | ||
use App\Utils\FormatUtils; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\MockObject\Exception; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(EntityProvider::class)] | ||
#[CoversClass(CalculationStateProvider::class)] | ||
class CalculationStateProviderTest extends TestCase | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public function testWithEntity(): void | ||
{ | ||
$entity = new CalculationState(); | ||
$entity->setCode('code'); | ||
$provider = $this->createProvider($entity); | ||
|
||
$actual = $provider->statesCount(); | ||
self::assertSame(1, $actual); | ||
|
||
$actual = $provider->state(); | ||
self::assertSame($entity, $actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function testWithoutEntity(): void | ||
{ | ||
$provider = $this->createProvider(); | ||
|
||
$actual = $provider->statesCount(); | ||
self::assertSame(0, $actual); | ||
|
||
$actual = $provider->state(); | ||
self::assertNull($actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
private function createProvider(?CalculationState $entity = null): CalculationStateProvider | ||
{ | ||
$entities = $entity instanceof CalculationState ? [$entity] : []; | ||
$repository = $this->createMock(UserRepository::class); | ||
$repository->expects(self::any()) | ||
->method('findBy') | ||
->willReturn($entities); | ||
|
||
$repository->expects(self::any()) | ||
->method('findAll') | ||
->willReturn($entities); | ||
|
||
$manager = $this->createMock(EntityManagerInterface::class); | ||
$manager->expects(self::any()) | ||
->method('getRepository') | ||
->willReturn($repository); | ||
|
||
$generator = Factory::create(FormatUtils::DEFAULT_LOCALE); | ||
|
||
return new CalculationStateProvider($generator, $manager); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Faker; | ||
|
||
use App\Entity\Category; | ||
use App\Faker\CategoryProvider; | ||
use App\Faker\EntityProvider; | ||
use App\Faker\Factory; | ||
use App\Repository\CategoryRepository; | ||
use App\Utils\FormatUtils; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\MockObject\Exception; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(EntityProvider::class)] | ||
#[CoversClass(CategoryProvider::class)] | ||
class CategoryProviderTest extends TestCase | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public function testWithEntity(): void | ||
{ | ||
$entity = new Category(); | ||
$entity->setCode('code'); | ||
$provider = $this->createProvider($entity); | ||
|
||
$actual = $provider->categoriesCount(); | ||
self::assertSame(1, $actual); | ||
|
||
$actual = $provider->category(); | ||
self::assertSame($entity, $actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function testWithoutEntity(): void | ||
{ | ||
$provider = $this->createProvider(); | ||
|
||
$actual = $provider->categoriesCount(); | ||
self::assertSame(0, $actual); | ||
|
||
$actual = $provider->category(); | ||
self::assertNull($actual); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
private function createProvider(?Category $entity = null): CategoryProvider | ||
{ | ||
$entities = $entity instanceof Category ? [$entity] : []; | ||
$repository = $this->createMock(CategoryRepository::class); | ||
$repository->expects(self::any()) | ||
->method('findBy') | ||
->willReturn($entities); | ||
|
||
$repository->expects(self::any()) | ||
->method('findAll') | ||
->willReturn($entities); | ||
|
||
$manager = $this->createMock(EntityManagerInterface::class); | ||
$manager->expects(self::any()) | ||
->method('getRepository') | ||
->willReturn($repository); | ||
|
||
$generator = Factory::create(FormatUtils::DEFAULT_LOCALE); | ||
|
||
return new CategoryProvider($generator, $manager); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/* | ||
* This file is part of the Calculation package. | ||
* | ||
* (c) bibi.nu <bibi@bibi.nu> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Faker; | ||
|
||
use App\Faker\CustomAddress; | ||
use App\Faker\Factory; | ||
use App\Utils\FormatUtils; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(CustomAddress::class)] | ||
class CustomAddressTest extends TestCase | ||
{ | ||
public function testCustomAddress(): void | ||
{ | ||
$generator = Factory::create(FormatUtils::DEFAULT_LOCALE); | ||
$customAddress = new CustomAddress($generator); | ||
$actual = $customAddress->zipCity(); | ||
self::assertNotEmpty($actual); | ||
} | ||
} |
Oops, something went wrong.