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 a6c0cfc

Browse files
created logger test cases
1 parent 6f71dc1 commit a6c0cfc

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Bug-Tracking-App
2+
3+
vendor\bin\phpunit --testdox test

‎Test/Unit/ApplicationTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,13 @@ public function testItCanGetInstanceOfApp()
1111
{
1212
static::assertInstanceOf(App::class, new App());
1313
}
14+
15+
public function testItCanGetBasicAppDataSetFromAppClass()
16+
{
17+
$app = new App();
18+
self::assertTrue($app->isRunningFromConsole());
19+
self::assertSame('local', $app->getEnvironment());
20+
self::assertNotNull($app->getLogPath());
21+
$this->assertInstanceOf(\DateTime::class, $app->getServerTime());
22+
}
1423
}

‎Test/Unit/LoggerTest.php‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
namespace Test\Unit;
3+
4+
use App\Contracts\LoggerInterface;
5+
use App\Exception\InvalidLogLevelArgument;
6+
use App\Helpers\App;
7+
use App\Logger\Logger;
8+
use App\Logger\Loglevel;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class LoggerTest extends TestCase
12+
{
13+
private $logger;
14+
protected function setUp()
15+
{
16+
$this->logger = new Logger();
17+
parent::setUp();
18+
}
19+
20+
protected function tearDown()
21+
{
22+
unset($this->logger);
23+
}
24+
25+
public function testItImplementsTheLoggerInterface()
26+
{
27+
self::assertInstanceOf(LoggerInterface::class, $this->logger);
28+
}
29+
30+
public function testItCanCreateDifferentTypesOfLogLevels()
31+
{
32+
$app = new App();
33+
//Logging the the application
34+
$this->logger->info('Testing Info Logs');
35+
$this->logger->Error('Testing Error Logs');
36+
$this->logger->log(Loglevel::ALERT,'Testing Alert Logs');
37+
38+
//creating a file and checking if file exists
39+
$fileName = sprintf("%s/%s-%s.log", $app->getLogPath(), 'local', date("j.n.Y"));
40+
self::assertFileExists($fileName);
41+
42+
// checking if the log file contains the above given string
43+
$contentOfLogFile = file_get_contents($fileName);
44+
self::assertStringContainsString('Testing Info Logs', $contentOfLogFile);
45+
self::assertStringContainsString('Testing Error Logs', $contentOfLogFile);
46+
self::assertStringContainsString('Testing Alert Logs', $contentOfLogFile);
47+
48+
// deleting the file and checking if the file has been deleted
49+
unlink($fileName);
50+
self::assertFileNotExists($fileName);
51+
}
52+
53+
public function testIfThrowsInvalidLogLevelArgumentExceptionWhenGivenAWrongLogLevel()
54+
{
55+
self::expectException(InvalidLogLevelArgument::class);
56+
$this->logger->log('invalid', 'testing invalid log level');
57+
}
58+
}

‎phpunit.xml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
</testsuite>
2020
</testsuites>
2121

22+
<php>
23+
<const name="PHPUNIT_RUNNING" value="true"/>
24+
</php>
2225

2326
</phpunit>

0 commit comments

Comments
(0)

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