Skip to content

Commit 78eccd3

Browse files
committed
add more tests and fixed RecordPing.php
1 parent a16fc4e commit 78eccd3

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

Diff for: src/Entity/RecordPing.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DateTimeImmutable;
66
use Doctrine\ORM\Mapping as ORM;
77
use BugCatcher\Repository\RecordPingRepository;
8+
use LogicException;
89
use Symfony\Component\HttpFoundation\Response;
910

1011
#[ORM\Entity(repositoryClass: RecordPingRepository::class)]
@@ -27,21 +28,16 @@ public function getStatusCode(): ?string {
2728
return $this->statusCode;
2829
}
2930

30-
public function setStatusCode(string $statusCode): static {
31-
$this->statusCode = $statusCode;
32-
33-
return $this;
34-
}
3531

3632
function calculateHash(): ?string {
37-
return null;
33+
throw new LogicException("Ping record does not have hash");
3834
}
3935

4036
function getComponentName(): string {
41-
return "RecordLog";
37+
throw new LogicException("Ping record does not have component name");
4238
}
4339

4440
function isError(): bool {
45-
return $this->getStatus() != Response::HTTP_OK;
41+
return $this->statusCode != Response::HTTP_OK;
4642
}
4743
}

Diff for: tests/Unit/Entity/RecordPingTest.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Jozef Môstka
5+
* Date: 8. 10. 2024
6+
* Time: 21:37
7+
*/
8+
9+
namespace BugCatcher\Tests\Unit\Entity;
10+
11+
use BugCatcher\Entity\Project;
12+
use BugCatcher\Entity\RecordPing;
13+
use LogicException;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class RecordPingTest extends TestCase
17+
{
18+
public function testCalculateHash(): void
19+
{
20+
$record = new RecordPing(new Project(), "200");
21+
$this->expectException(LogicException::class);
22+
$record->calculateHash();
23+
}
24+
25+
public function testComponentName(): void
26+
{
27+
$record = new RecordPing(new Project(), "200");
28+
$this->expectException(LogicException::class);
29+
$record->getComponentName();
30+
}
31+
32+
public function testIsNotError(): void
33+
{
34+
$record = new RecordPing(new Project(), "200");
35+
$this->assertFalse($record->isError());
36+
}
37+
38+
public function testIsError(): void
39+
{
40+
$record = new RecordPing(new Project(), "500");
41+
$this->assertTrue($record->isError());
42+
}
43+
44+
}

0 commit comments

Comments
 (0)