Skip to content

Commit 2b8c0c0

Browse files
committed
Add tests
1 parent e7440aa commit 2b8c0c0

File tree

16 files changed

+468
-79
lines changed

16 files changed

+468
-79
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/vendor/
22
composer.lock
33
vendor
4+
tests/_output
5+
6+
/.idea/

Plugin.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,7 @@ class Plugin implements PluginEntryPointInterface
1111
public function __invoke(RegistrationInterface $psalm, ?SimpleXMLElement $config = null)
1212
{
1313
$psalm->addStubFile(__DIR__ . '/stubs/LoggerInterface.php');
14-
15-
// This is plugin entry point. You can initialize things you need here,
16-
// and hook them into psalm using RegistrationInterface
17-
//
18-
// Here's some examples:
19-
// 1. Add a stub file
20-
// ```php
21-
// $psalm->addStubFile(__DIR__ . '/stubs/YourStub.php');
22-
// ```
23-
24-
// Psalm allows arbitrary content to be stored under you plugin entry in
25-
// its config file, psalm.xml, so you plugin users can put some configiration
26-
// values there. They will be provided to your plugin entry point in $config
27-
// parameter, as a SimpleXmlElement object. If there's no configuration present,
28-
// null will be passed instead.
14+
$psalm->addStubFile(__DIR__ . '/stubs/AbstractLogger.php');
15+
$psalm->addStubFile(__DIR__ . '/stubs/LoggerTrait.php');
2916
}
3017
}

codeception.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace: SfpTest\Psalm\PsrLogPlugin
2+
paths:
3+
tests: tests
4+
output: tests/_output
5+
data: tests/_data
6+
support: tests/_support
7+
envs: tests/_envs
8+
actor_suffix: Tester
9+
extensions:
10+
enabled:
11+
- Codeception\Extension\RunFailed

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
"vimeo/psalm": "^3.5"
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "^8.2",
18-
"squizlabs/php_codesniffer": "^3.3",
1917
"psr/log": "^1.1",
18+
"squizlabs/php_codesniffer": "^3.3",
2019
"codeception/base": "^3.1",
2120
"weirdan/codeception-psalm-module": "^0.2.2"
2221
},
@@ -32,7 +31,10 @@
3231
},
3332
"autoload-dev": {
3433
"psr-4": {
35-
"SfpTest\\Psalm\\PsrLogPlugin\\": "tests"
34+
"SfpTest\\Psalm\\PsrLogPlugin\\": [
35+
"tests/_support",
36+
"tests/acceptance"
37+
]
3638
}
3739
},
3840
"scripts" : {
@@ -44,7 +46,6 @@
4446
"analyze": "psalm",
4547
"cs-check": "phpcs",
4648
"cs-fix": "phpcbf",
47-
"test": "phpunit --colors=always",
48-
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
49+
"test": "codecept run -v"
4950
}
5051
}

stubs/AbstractLogger.php

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
namespace Psr\Log;
4+
5+
/**
6+
* This is a simple Logger implementation that other Loggers can inherit from.
7+
*
8+
* It simply delegates all log-level-specific methods to the `log` method to
9+
* reduce boilerplate code that a simple Logger that does the same thing with
10+
* messages regardless of the error level has to implement.
11+
*/
12+
abstract class AbstractLogger implements LoggerInterface
13+
{
14+
/**
15+
* System is unusable.
16+
*
17+
* @param string $message
18+
* @param array{exception?: \Exception} $context
19+
*
20+
* @return void
21+
*/
22+
public function emergency($message, array $context = array())
23+
{
24+
$this->log(LogLevel::EMERGENCY, $message, $context);
25+
}
26+
27+
/**
28+
* Action must be taken immediately.
29+
*
30+
* Example: Entire website down, database unavailable, etc. This should
31+
* trigger the SMS alerts and wake you up.
32+
*
33+
* @param string $message
34+
* @param array{exception?: \Exception} $context
35+
*
36+
* @return void
37+
*/
38+
public function alert($message, array $context = array())
39+
{
40+
$this->log(LogLevel::ALERT, $message, $context);
41+
}
42+
43+
/**
44+
* Critical conditions.
45+
*
46+
* Example: Application component unavailable, unexpected exception.
47+
*
48+
* @param string $message
49+
* @param array{exception?: \Exception} $context
50+
*
51+
* @return void
52+
*/
53+
public function critical($message, array $context = array())
54+
{
55+
$this->log(LogLevel::CRITICAL, $message, $context);
56+
}
57+
58+
/**
59+
* Runtime errors that do not require immediate action but should typically
60+
* be logged and monitored.
61+
*
62+
* @param string $message
63+
* @param array{exception?: \Exception} $context
64+
*
65+
* @return void
66+
*/
67+
public function error($message, array $context = array())
68+
{
69+
$this->log(LogLevel::ERROR, $message, $context);
70+
}
71+
72+
/**
73+
* Exceptional occurrences that are not errors.
74+
*
75+
* Example: Use of deprecated APIs, poor use of an API, undesirable things
76+
* that are not necessarily wrong.
77+
*
78+
* @param string $message
79+
* @param array{exception?: \Exception} $context
80+
*
81+
* @return void
82+
*/
83+
public function warning($message, array $context = array())
84+
{
85+
$this->log(LogLevel::WARNING, $message, $context);
86+
}
87+
88+
/**
89+
* Normal but significant events.
90+
*
91+
* @param string $message
92+
* @param array{exception?: \Exception} $context
93+
*
94+
* @return void
95+
*/
96+
public function notice($message, array $context = array())
97+
{
98+
$this->log(LogLevel::NOTICE, $message, $context);
99+
}
100+
101+
/**
102+
* Interesting events.
103+
*
104+
* Example: User logs in, SQL logs.
105+
*
106+
* @param string $message
107+
* @param array{exception?: \Exception} $context
108+
*
109+
* @return void
110+
*/
111+
public function info($message, array $context = array())
112+
{
113+
$this->log(LogLevel::INFO, $message, $context);
114+
}
115+
116+
/**
117+
* Detailed debug information.
118+
*
119+
* @param string $message
120+
* @param array{exception?: \Exception} $context
121+
*
122+
* @return void
123+
*/
124+
public function debug($message, array $context = array())
125+
{
126+
$this->log(LogLevel::DEBUG, $message, $context);
127+
}
128+
}

stubs/LoggerInterface.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface LoggerInterface
2323
* System is unusable.
2424
*
2525
* @param string $message
26-
* @param array $context
26+
* @param array{exception?: \Exception} $context
2727
*
2828
* @return void
2929
*/
@@ -36,7 +36,7 @@ public function emergency($message, array $context = array());
3636
* trigger the SMS alerts and wake you up.
3737
*
3838
* @param string $message
39-
* @param array $context
39+
* @param array{exception?: \Exception} $context
4040
*
4141
* @return void
4242
*/
@@ -48,7 +48,7 @@ public function alert($message, array $context = array());
4848
* Example: Application component unavailable, unexpected exception.
4949
*
5050
* @param string $message
51-
* @param array $context
51+
* @param array{exception?: \Exception} $context
5252
*
5353
* @return void
5454
*/
@@ -59,7 +59,7 @@ public function critical($message, array $context = array());
5959
* be logged and monitored.
6060
*
6161
* @param string $message
62-
* @param array $context
62+
* @param array{exception?: \Exception} $context
6363
*
6464
* @return void
6565
*/
@@ -72,7 +72,7 @@ public function error($message, array $context = array());
7272
* that are not necessarily wrong.
7373
*
7474
* @param string $message
75-
* @param array $context
75+
* @param array{exception?: \Exception} $context
7676
*
7777
* @return void
7878
*/
@@ -82,7 +82,7 @@ public function warning($message, array $context = array());
8282
* Normal but significant events.
8383
*
8484
* @param string $message
85-
* @param array $context
85+
* @param array{exception?: \Exception} $context
8686
*
8787
* @return void
8888
*/
@@ -94,7 +94,7 @@ public function notice($message, array $context = array());
9494
* Example: User logs in, SQL logs.
9595
*
9696
* @param string $message
97-
* @param array $context
97+
* @param array{exception?: \Exception} $context
9898
*
9999
* @return void
100100
*/
@@ -104,7 +104,7 @@ public function info($message, array $context = array());
104104
* Detailed debug information.
105105
*
106106
* @param string $message
107-
* @param array $context
107+
* @param array{exception?: \Exception} $context
108108
*
109109
* @return void
110110
*/
@@ -115,7 +115,7 @@ public function debug($message, array $context = array());
115115
*
116116
* @param mixed $level
117117
* @param string $message
118-
* @param array $context
118+
* @param array{exception?: \Exception} $context
119119
*
120120
* @return void
121121
*

0 commit comments

Comments
 (0)