Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Apr 2, 2024
1 parent a24e959 commit 7a6a4d1
Show file tree
Hide file tree
Showing 12 changed files with 482 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/end-to-end/event/_files/DataProviderErrorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Event;

use function trigger_error;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class DataProviderErrorTest extends TestCase
{
public static function values(): array
{
trigger_error('message', E_USER_ERROR);

return [[true], [true]];
}

#[DataProvider('values')]
public function testSuccess(bool $value): void
{
$this->assertTrue($value);
}
}
30 changes: 30 additions & 0 deletions tests/end-to-end/event/_files/DataProviderNoticeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Event;

use function trigger_error;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class DataProviderNoticeTest extends TestCase
{
public static function values(): array
{
trigger_error('message', E_USER_NOTICE);

return [[true], [true]];
}

#[DataProvider('values')]
public function testSuccess(bool $value): void
{
$this->assertTrue($value);
}
}
30 changes: 30 additions & 0 deletions tests/end-to-end/event/_files/DataProviderPhpDeprecationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Event;

use function strlen;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class DataProviderPhpDeprecationTest extends TestCase
{
public static function values(): array
{
strlen(null);

return [[true], [true]];
}

#[DataProvider('values')]
public function testSuccess(bool $value): void
{
$this->assertTrue($value);
}
}
33 changes: 33 additions & 0 deletions tests/end-to-end/event/_files/DataProviderPhpNoticeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Event;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class DataProviderPhpNoticeTest extends TestCase
{
public static function values(): array
{
$f = static function (): void
{
};

$a = &$f();

return [[true], [true]];
}

#[DataProvider('values')]
public function testSuccess(bool $value): void
{
$this->assertTrue($value);
}
}
29 changes: 29 additions & 0 deletions tests/end-to-end/event/_files/DataProviderPhpWarningTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Event;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class DataProviderPhpWarningTest extends TestCase
{
public static function values(): array
{
$a = $b;

return [[true], [true]];
}

#[DataProvider('values')]
public function testSuccess(bool $value): void
{
$this->assertTrue($value);
}
}
30 changes: 30 additions & 0 deletions tests/end-to-end/event/_files/DataProviderWarningTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Event;

use function trigger_error;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class DataProviderWarningTest extends TestCase
{
public static function values(): array
{
trigger_error('message', E_USER_WARNING);

return [[true], [true]];
}

#[DataProvider('values')]
public function testSuccess(bool $value): void
{
$this->assertTrue($value);
}
}
43 changes: 43 additions & 0 deletions tests/end-to-end/event/data-provider-error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
The right events are emitted in the right order for a successful test that uses a data provider which triggers E_USER_ERROR
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = __DIR__ . '/_files/DataProviderErrorTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Configured
Data Provider Method Called (PHPUnit\TestFixture\Event\DataProviderErrorTest::values for test method PHPUnit\TestFixture\Event\DataProviderErrorTest::testSuccess)
Data Provider Method Called (PHPUnit\TestFixture\Event\DataProviderErrorTest::values for test method PHPUnit\TestFixture\Event\DataProviderErrorTest::testSuccess)
Data Provider Triggered Error (PHPUnit\TestFixture\Event\DataProviderErrorTest::values)
message
Data Provider Method Finished for PHPUnit\TestFixture\Event\DataProviderErrorTest::testSuccess:
- PHPUnit\TestFixture\Event\DataProviderErrorTest::values
Data Provider Method Finished for PHPUnit\TestFixture\Event\DataProviderErrorTest::testSuccess:
- PHPUnit\TestFixture\Event\DataProviderErrorTest::values
Test Triggered PHPUnit Error (PHPUnit\TestFixture\Event\DataProviderErrorTest::testSuccess)
The data provider specified for PHPUnit\TestFixture\Event\DataProviderErrorTest::testSuccess is invalid
E_USER_ERROR was triggered
Test Runner Triggered Warning (No tests found in class "PHPUnit\TestFixture\Event\DataProviderErrorTest".)
Test Suite Loaded (0 tests)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (0 tests)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 2)
51 changes: 51 additions & 0 deletions tests/end-to-end/event/data-provider-notice.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
The right events are emitted in the right order for a successful test that uses a data provider which triggers E_USER_NOTICE
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = __DIR__ . '/_files/DataProviderNoticeTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Configured
Data Provider Method Called (PHPUnit\TestFixture\Event\DataProviderNoticeTest::values for test method PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess)
Data Provider Method Called (PHPUnit\TestFixture\Event\DataProviderNoticeTest::values for test method PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess)
Data Provider Triggered Notice (PHPUnit\TestFixture\Event\DataProviderNoticeTest::values)
message
Data Provider Method Finished for PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess:
- PHPUnit\TestFixture\Event\DataProviderNoticeTest::values
Data Provider Method Finished for PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess:
- PHPUnit\TestFixture\Event\DataProviderNoticeTest::values
Test Suite Loaded (2 tests)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (2 tests)
Test Suite Started (PHPUnit\TestFixture\Event\DataProviderNoticeTest, 2 tests)
Test Suite Started (PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess, 2 tests)
Test Preparation Started (PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess#0)
Test Prepared (PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess#0)
Test Passed (PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess#0)
Test Finished (PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess#0)
Test Preparation Started (PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess#1)
Test Prepared (PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess#1)
Test Passed (PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess#1)
Test Finished (PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess#1)
Test Suite Finished (PHPUnit\TestFixture\Event\DataProviderNoticeTest::testSuccess, 2 tests)
Test Suite Finished (PHPUnit\TestFixture\Event\DataProviderNoticeTest, 2 tests)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 0)
53 changes: 53 additions & 0 deletions tests/end-to-end/event/data-provider-php-deprecation.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--TEST--
The right events are emitted in the right order for a successful test that uses a data provider which triggers E_DEPRECATED
--XFAIL--
"Data Provider Triggered PHP Deprecation" event is not emitted
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = __DIR__ . '/_files/DataProviderPhpDeprecationTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Configured
Data Provider Method Called (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::values for test method PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess)
Data Provider Method Called (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::values for test method PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess)
Data Provider Triggered PHP Deprecation (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::values, issue triggered by first-party code calling into first-party code)
strlen(): Passing null to parameter #1 ($string) of type string is deprecated
Data Provider Method Finished for PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess:
- PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::values
Data Provider Method Finished for PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess:
- PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::values
Test Suite Loaded (2 tests)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (2 tests)
Test Suite Started (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest, 2 tests)
Test Suite Started (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess, 2 tests)
Test Preparation Started (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess#0)
Test Prepared (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess#0)
Test Passed (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess#0)
Test Finished (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess#0)
Test Preparation Started (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess#1)
Test Prepared (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess#1)
Test Passed (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess#1)
Test Finished (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess#1)
Test Suite Finished (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest::testSuccess, 2 tests)
Test Suite Finished (PHPUnit\TestFixture\Event\DataProviderPhpDeprecationTest, 2 tests)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 0)
51 changes: 51 additions & 0 deletions tests/end-to-end/event/data-provider-php-notice.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
The right events are emitted in the right order for a successful test that uses a data provider which triggers E_NOTICE
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;
$_SERVER['argv'][] = __DIR__ . '/_files/DataProviderPhpNoticeTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);

print file_get_contents($traceFile);

unlink($traceFile);
--EXPECTF--
PHPUnit Started (PHPUnit %s using %s)
Test Runner Configured
Data Provider Method Called (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::values for test method PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess)
Data Provider Method Called (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::values for test method PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess)
Data Provider Triggered PHP Notice (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::values)
Only variables should be assigned by reference
Data Provider Method Finished for PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess:
- PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::values
Data Provider Method Finished for PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess:
- PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::values
Test Suite Loaded (2 tests)
Event Facade Sealed
Test Runner Started
Test Suite Sorted
Test Runner Execution Started (2 tests)
Test Suite Started (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest, 2 tests)
Test Suite Started (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess, 2 tests)
Test Preparation Started (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess#0)
Test Prepared (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess#0)
Test Passed (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess#0)
Test Finished (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess#0)
Test Preparation Started (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess#1)
Test Prepared (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess#1)
Test Passed (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess#1)
Test Finished (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess#1)
Test Suite Finished (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest::testSuccess, 2 tests)
Test Suite Finished (PHPUnit\TestFixture\Event\DataProviderPhpNoticeTest, 2 tests)
Test Runner Execution Finished
Test Runner Finished
PHPUnit Finished (Shell Exit Code: 0)
Loading

0 comments on commit 7a6a4d1

Please sign in to comment.