Skip to content

Commit

Permalink
Tests: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Nov 28, 2023
1 parent 0dd25c6 commit c17b7b5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions tests/Cases/AbstractMenuItemsContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testItems(): void
], $container->getItems());
}

public function testGetItem_direct(): void
public function testGetItemDirect(): void
{
$menu = $this->createMockMenu();
$linkGenerator = $this->createMockLinkGenerator();
Expand All @@ -59,7 +59,7 @@ public function testGetItem_direct(): void
Assert::same($item, $container->getItem('item'));
}

public function testGetItem_path(): void
public function testGetItemPath(): void
{
$menu = $this->createMockMenu();
$linkGenerator = $this->createMockLinkGenerator();
Expand Down
5 changes: 3 additions & 2 deletions tests/Cases/DI/MenuExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Cases\DI;

use Contributte\MenuControl\IMenu;
use Contributte\MenuControl\MenuContainer;
use Contributte\MenuControl\UI\MenuComponent;
use Contributte\MenuControl\UI\MenuComponentFactory;
Expand All @@ -24,7 +25,7 @@
final class MenuExtensionTest extends AbstractTestCase
{

public function testDI(): void
public function testDi(): void
{
$dic = $this->createContainer();

Expand All @@ -38,7 +39,7 @@ public function testDataItems(): void
$dic = $this->createContainer();

$container = $dic->getService('menu.container');
/** @var \Contributte\MenuControl\IMenu $menu */
/** @var IMenu $menu */
$menu = $container->getMenu('default');

$item = $menu->getItem('Homepage');
Expand Down
8 changes: 4 additions & 4 deletions tests/Cases/LinkGenerator/NetteLinkGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
final class NetteLinkGeneratorTest extends AbstractTestCase
{

public function testLink_action(): void
public function testLinkAction(): void
{
$request = $this->createMockHttpRequest();
$netteLinkGenerator = $this->createMockNetteLinkGenerator(function (MockInterface $netteLinkGenerator): void {
Expand All @@ -29,7 +29,7 @@ public function testLink_action(): void
Assert::same('/', $linkGenerator->link($item));
}

public function testAbsoluteLink_action(): void
public function testAbsoluteLinkAction(): void
{
$request = $this->createMockHttpRequest(function (MockInterface $request): void {
$request->shouldReceive('getUrl')->andReturn(
Expand All @@ -54,7 +54,7 @@ public function testAbsoluteLink_action(): void
Assert::same('https://localhost/', $linkGenerator->absoluteLink($item));
}

public function testLink_link(): void
public function testLinkLink(): void
{
$request = $this->createMockHttpRequest();
$netteLinkGenerator = $this->createMockNetteLinkGenerator(function (MockInterface $netteLinkGenerator): void {
Expand All @@ -71,7 +71,7 @@ public function testLink_link(): void
Assert::same('/', $linkGenerator->link($item));
}

public function testLink_empty(): void
public function testLinkEmpty(): void
{
$request = $this->createMockHttpRequest();
$netteLinkGenerator = $this->createMockNetteLinkGenerator();
Expand Down
2 changes: 1 addition & 1 deletion tests/Cases/Loaders/DefaultMenuLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
final class DefaultMenuLoaderTest extends AbstractTestCase
{

public function testLoad_simple(): void
public function testLoadSimple(): void
{
Environment::$checkAssertions = false;

Expand Down
10 changes: 5 additions & 5 deletions tests/Cases/MenuItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testIsAllowed(): void
Assert::true($item->isAllowed());
}

public function testIsActive_not_allowed(): void
public function testIsActiveNotAllowed(): void
{
$linkGenerator = $this->createMockLinkGenerator();
$translator = $this->createMockTranslator();
Expand All @@ -64,7 +64,7 @@ public function testIsActive_not_allowed(): void
Assert::false($item->isActive());
}

public function testIsActive_action_current(): void
public function testIsActiveActionCurrent(): void
{
$translator = $this->createMockTranslator();
$itemFactory = $this->createMockMenuItemFactory();
Expand All @@ -91,7 +91,7 @@ public function testIsActive_action_current(): void
Assert::true($item->isActive());
}

public function testIsActive_include(): void
public function testIsActiveInclude(): void
{
$translator = $this->createMockTranslator();
$itemFactory = $this->createMockMenuItemFactory();
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testIsActive_include(): void
Assert::true($item->isActive());
}

public function testIsActive_active_child(): void
public function testIsActiveActiveChild(): void
{
$menu = $this->createMockMenu();
$linkGenerator = $this->createMockLinkGenerator();
Expand Down Expand Up @@ -219,7 +219,7 @@ public function testGetRealLink(): void
Assert::same('#', $item->getRealLink());
}

public function testGetRealAbsoluteLink_80_port(): void
public function testGetRealAbsoluteLink80Port(): void
{
$menu = $this->createMockMenu();
$translator = $this->createMockTranslator();
Expand Down
10 changes: 7 additions & 3 deletions tests/Toolkit/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
use Contributte\MenuControl\Loaders\IMenuLoader;
use Contributte\MenuControl\Security\IAuthorizator;
use Mockery;
use Mockery\MockInterface;
use Nette\Application\Application;
use Nette\Application\LinkGenerator;
use Nette\Application\UI\Presenter;
use Nette\Http\Request;
use Nette\Http\UrlScript;
use Nette\Localization\Translator;
use Tester;
use Tester\TestCase;

abstract class AbstractTestCase extends Tester\TestCase
abstract class AbstractTestCase extends TestCase
{

public function tearDown(): void
Expand Down Expand Up @@ -105,7 +106,10 @@ protected function createMockHttpUrl(?callable $fn = null): UrlScript
return $this->createMock(UrlScript::class, $fn);
}

private function createMock(string $type, ?callable $fn = null, ?array $args = null, bool $partial = false)
/**
* @param mixed[]|null $args
*/
private function createMock(string $type, ?callable $fn = null, ?array $args = null, bool $partial = false): MockInterface
{
$mock = $args === null ? Mockery::mock($type) : Mockery::mock($type, $args);

Expand Down

0 comments on commit c17b7b5

Please sign in to comment.