Skip to content

Commit

Permalink
feat: Fixing php stan
Browse files Browse the repository at this point in the history
  • Loading branch information
KminekMatej committed Dec 7, 2024
1 parent 76bfaf2 commit 19a4c82
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private function getStatusSetId(): int

public function createRecord(): array
{
//use creator from recorManager - can create status or statusSet
throw new \Nette\NotImplementedException();
}

public function mockRecord(): void
Expand Down
2 changes: 1 addition & 1 deletion app/module/autotest/app/attendance/AttendanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testUnknownEvent(): void

public function createRecord(): array
{
//attendance are never created solely, always just posted to some event
throw new \Nette\NotImplementedException();
}

public function mockRecord(): array
Expand Down
2 changes: 1 addition & 1 deletion app/module/autotest/app/authentication/IsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function mockChanges(): array

public function createRecord(): array
{
//not used in this test
throw new \Nette\NotImplementedException();
}

protected function getBasePath(): string
Expand Down
8 changes: 4 additions & 4 deletions app/module/autotest/app/debt/DebtTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testGet(): void
public function testCRUDSingular(): void
{
$this->authorizeAdmin();
$recordId = $this->createRecord();
$recordId = $this->createRecord()["id"];

$this->request($this->getBasePath() . "/" . $recordId)->expect(200, "array");

Expand Down Expand Up @@ -127,7 +127,7 @@ public function testBlankCaption(): void
$data["caption"] = "";
$this->request($this->getBasePath(), "POST", $data)->expect(400);

$recordId = $this->createRecord();
$recordId = $this->createRecord()["id"];
$this->request($this->getBasePath() . "/" . $recordId, "PUT", ["caption" => ""])->expect(400);
}

Expand All @@ -146,7 +146,7 @@ public function testDebtNegative(): void
$data["amount"] = -13;
$this->request($this->getBasePath(), "POST", $data)->expect(400);

$recordId = $this->createRecord();
$recordId = $this->createRecord()["id"];
$this->request($this->getBasePath() . "/" . $recordId, "PUT", ["amount" => "-14"])->expect(400);
}

Expand All @@ -173,7 +173,7 @@ public function testTeamOwesMe(): void
public function testCRUDPlural(): void
{
$this->authorizeAdmin();
$recordId = $this->createRecord();
$recordId = $this->createRecord()["id"];

$this->request($this->getBasePath() . "s/" . $recordId)->expect(200, "array");

Expand Down
2 changes: 1 addition & 1 deletion app/module/autotest/app/event/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testCreateMultiple(): void

public function testCRUDSingular(): void
{
$recordId = $this->createRecord();
$recordId = $this->createRecord()["id"];

$this->request($this->getBasePath() . "/" . $recordId)->expect(200, "array");
$this->request($this->getBasePath() . "/" . $recordId . "/history")->expect(200, "array");
Expand Down
2 changes: 1 addition & 1 deletion app/module/autotest/app/permission/PermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testGetPlural(): void

public function testCRUDSingular(): void
{
$recordId = $this->createRecord();
$recordId = $this->createRecord()["id"];

$this->request($this->getBasePath() . "/" . $recordId)->expect(200, "array");

Expand Down
4 changes: 2 additions & 2 deletions app/module/autotest/app/poll/PollTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testCRUDSingular(): void
{
$this->authorizeAdmin();

$recordId = $this->createRecord();
$recordId = $this->createRecord()["id"];

$this->request($this->getBasePath() . "/" . $recordId)->expect(200, "array");

Expand Down Expand Up @@ -72,7 +72,7 @@ public function testCRUDSingular(): void
public function testCrudForbidden(): void
{
$this->authorizeAdmin();
$pollId = $this->createRecord();
$pollId = $this->createRecord()["id"];
$this->createOptionsFor($pollId, 1);
$optionsData = $this->request($this->getBasePath() . "/$pollId/options")->expect(200, "array")->getData();//poll doesnt exist
$option = $optionsData[0];
Expand Down
6 changes: 3 additions & 3 deletions app/module/autotest/app/user/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testStatus(): void

public function testCRUD(): void
{
$recordId = $this->createRecord();
$recordId = $this->createRecord()["id"];

$this->request($this->getBasePath() . "/" . $recordId)->expect(200, "array");

Expand Down Expand Up @@ -266,7 +266,7 @@ public function testUpdateFailures(): void
$adminData = $this->request($this->getBasePath() . "/1", "PUT", ["roles" => ["USR"]])->expect(200)->getData();
Assert::contains("SUPER", $adminData["roles"]);

$userId = $this->createRecord();
$userId = $this->createRecord()["id"];

$this->authorizeUser();
$this->request($this->getBasePath() . "/$userId", "PUT", $this->mockChanges())->expect(403);
Expand Down Expand Up @@ -312,7 +312,7 @@ public function testAvatar(): void
)->expect(400);

$this->authorizeAdmin();
$userId = $this->createRecord();
$userId = $this->createRecord()["id"];

$this->authorizeUser();
$this->request(
Expand Down
9 changes: 9 additions & 0 deletions app/module/autotest/entity/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public function deleteRecord($recordId): void
$this->recordManager->deleteRecord($this->getBasePath(), $recordId);
}

protected function change(int $recordId, ?array $changes = null)
{
$changes = $changes ?: $this->mockChanges();

$changedData = $this->request($this->getBasePath() . "/" . $recordId, "PUT", $changes)->expect(200, "array")->getData();

$this->assertObjectEquality($changes, $changedData);
}

//*************** COMMON TESTS, SAME FOR ALL MODULES

public function testUnauthorized()
Expand Down
9 changes: 0 additions & 9 deletions app/module/autotest/entity/RequestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,6 @@ protected function tearDown(): void
$this->logs = [];
}

protected function change(int $recordId, ?array $changes = null)
{
$changes = $changes ?: $this->mockChanges();

$changedData = $this->request($this->getBasePath() . "/" . $recordId, "PUT", $changes)->expect(200, "array")->getData();

$this->assertObjectEquality($changes, $changedData);
}

/** @return SimpleResponse */
public function request($url, $method = "GET", $data = [], $responseClass = null)
{
Expand Down
6 changes: 4 additions & 2 deletions app/module/autotest/entity/UITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Tymy\Module\Autotest;

use Nette\Application\IPresenter;
use Nette\Application\UI\Presenter;
use Tester\DomQuery;
use Tymy\Module\Autotest\Entity\Assert;
use Tymy\Module\Core\Presenter\Front\BasePresenter;

abstract class UITest extends RequestCase
{
protected BasePresenter $presenter;
protected IPresenter $presenter;
protected string $presenterName;

protected abstract function getPresenter(): string;
Expand All @@ -17,6 +18,7 @@ protected function setUp()
{
$this->presenterName = "{$this->getModule()}:{$this->getPresenter()}";
$this->presenter = $this->presenterFactory->createPresenter($this->presenterName);
assert($this->presenter instanceof Presenter);
$this->presenter->autoCanonicalize = false;

parent::setUp();
Expand Down

0 comments on commit 19a4c82

Please sign in to comment.