Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #17 - Error suppression operator is not fully honoured #18

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
!/.github/
/vendor/
/composer.lock
/**/.phpunit.result.cache
Bilge marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The printer's capabilities are exploited via `CapabilitiesTest`. However, this t

The real tests, also known as *functional tests*, are located in `test/functional`, written in PHPT format. PHPT is a [scarcely documented format](http://qa.php.net/phpt_details.php) designed to support [testing PHP itself](https://qa.php.net/write-test.php). An undocumented feature of PHPUnit is its limited support for a subset of the PHPT test specification, which we exploit to test PHPUnit itself with our printer implementation loaded.

To run the tests, simply specify `vendor/bin/phpunit -c test` on the command line from the project directory. By default, we run all the functional PHPT tests. To run `CapabilitiesTest` instead, specify `vendor/bin/phpunit -c test test/CapabilitiesTest`.
To run the tests, simply specify `vendor/bin/phpunit -c test` on the command line from the project directory. By default, we run all the functional PHPT tests. To run `CapabilitiesTest` instead, specify `vendor/bin/phpunit -c test test/CapabilitiesTest.php`.

### Writing a functional test

Expand Down
12 changes: 9 additions & 3 deletions src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,23 @@ public function trace(Event $event): void
$this->trace = new Trace($event->message(), $event->test()->file(), $event->test()->line());
}
if ($event instanceof PhpNoticeTriggered) {
$this->status ??= TestStatus::Notice;
if (!$event->wasSuppressed()) {
$this->status ??= TestStatus::Notice;
}

$this->trace = Trace::fromEvent($event);
}
if ($event instanceof PhpWarningTriggered) {
$this->status ??= TestStatus::Warning;
if (!$event->wasSuppressed()) {
$this->status ??= TestStatus::Warning;
}

$this->trace = Trace::fromEvent($event);
}
if ($event instanceof PhpDeprecationTriggered) {
$this->status ??= TestStatus::Deprecated;
if (!$event->wasSuppressed()) {
$this->status ??= TestStatus::Deprecated;
}

$this->trace = Trace::fromEvent($event);
}
Expand Down
16 changes: 16 additions & 0 deletions test/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public function testNotice(): void
self::assertTrue(true);
}

public function testSilencedNotice(): void
{
// Only variables should be assigned by reference.
@$foo = &self::provideData();

self::assertTrue(true);
}

public function testWarning(): void
{
// foreach() argument must be of type array|object.
Expand All @@ -82,6 +90,14 @@ function unserialize(string $data) {}
self::assertTrue(true);
}

public function testSilencedDeprecation(): void
{
// Passing null to parameter #1 ($string) of type string is deprecated
Bilge marked this conversation as resolved.
Show resolved Hide resolved
@trim(null);

self::assertTrue(true);
}

#[DataProvider('provideData')]

public function testDataProvider(): void
Expand Down
21 changes: 21 additions & 0 deletions test/functional/deprecation silenced.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Tests that when a test generates a deprecation that is suppressed, the deprecation is not printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testSilencedDeprecation$

--FILE_EXTERNAL--
../PHPUnit runner.php

--EXPECTF--
PHPUnit %s

Runtime: %s
Configuration: %s

100% . ScriptFUSIONTest\Pip\CapabilitiesTest::testSilencedDeprecation (%d ms)


Time: %s
%A
OK (1 test, 1 assertion)
21 changes: 21 additions & 0 deletions test/functional/notice silenced.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Tests that when a test generates a notice that is suppressed, the notice is not printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testSilencedNotice$

--FILE_EXTERNAL--
../PHPUnit runner.php

--EXPECTF--
PHPUnit %s

Runtime: %s
Configuration: %s

100% . ScriptFUSIONTest\Pip\CapabilitiesTest::testSilencedNotice (%d ms)


Time: %s
%A
OK (1 test, 1 assertion)
2 changes: 1 addition & 1 deletion test/functional/warning silenced.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PHPUnit %s
Runtime: %s
Configuration: %s

100% W ScriptFUSIONTest\Pip\CapabilitiesTest::testSilencedWarning (%d ms)
100% . ScriptFUSIONTest\Pip\CapabilitiesTest::testSilencedWarning (%d ms)


Time: %s
Expand Down