Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3784e43

Browse files
Written few tests fro BugReport, faling(obviously)
1 parent 448d8bf commit 3784e43

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

‎Test/Unit/RepositoryTest.php‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
declare(strict_types=1);
3+
namespace Test\Unit;
4+
5+
use App\Database\QueryBuilder;
6+
use App\Helpers\DbQueryBuilderFactory;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class RepositoryTest extends TestCase
10+
{
11+
/**
12+
* @var QueryBuilder $queryBuilder
13+
*/
14+
private $queryBuilder;
15+
16+
private $bugReportRepository;
17+
18+
protected function setUp()
19+
{
20+
$this->queryBuilder = DbQueryBuilderFactory::make('database', 'mysqli', ['db_name' => 'bug_app_testing']);
21+
$this->queryBuilder->beginTransaction();
22+
$this->bugReportRepository = new BugReportRepository($this->queryBuilder);
23+
parent::setUp();
24+
}
25+
26+
27+
protected function tearDown()
28+
{
29+
$this->queryBuilder->rollback();
30+
unset($this->queryBuilder);
31+
parent::tearDown();
32+
}
33+
34+
35+
36+
public function createBugReport():BugReport
37+
{
38+
$bugReport = new BugReport();
39+
$bugReport->setReportType('Type 2')->setLink('https://xyz-link.com')
40+
->setMessage('This is a dummy Message')->setEmail('john@xyz.com');
41+
42+
$newBugReport = $this->bugReportRepository->create($bugReport);
43+
return $newBugReport;
44+
}
45+
46+
47+
public function testItCanCreateRecordWithEntity()
48+
{
49+
$newBugReport = $this->createBugReport();
50+
51+
self::assertInstanceOf(BugReport::class, $newBugReport);
52+
self::assertNotEmpty( $newBugReport->getId());
53+
self::assertSame('Type 2', $newBugReport->getReportType);
54+
self::assertSame('https://xyz-link.com', $newBugReport->getLink);
55+
self::assertSame('This is a dummy Message', $newBugReport->getMessage);
56+
self::assertSame('john@xyz.com', $newBugReport->getEmail);
57+
}
58+
59+
60+
public function testItCanUpdateAGivenEntity()
61+
{
62+
$newBugReport = $this->createBugReport();
63+
$bugReport = $this->bugReportRepository->find($newBugReport->getId());
64+
65+
$bugReport->setMessage('This is from update method')->setLink('https://newlink.com/image.png');
66+
$updatedReport = $this->bugReportRepository->update($bugReport);
67+
68+
self::assertInstanceOf(BugReport::class, $updatedReport);
69+
self::assertSame('This is from update method', $updatedReport->getReportType);
70+
self::assertSame('https://newlink.com/image.png', $updatedReport->getLink);
71+
}
72+
73+
74+
public function testItCanDeleteAGivenEntity()
75+
{
76+
$newBugReport = $this->createBugReport();
77+
$this->bugReportRepository->delete($newBugReport);
78+
$bugReport = $this->bugReportRepository->find($newBugReport->getId());
79+
80+
self::assertNull($bugReport);
81+
}
82+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /