<?php namespace nur\t; use Exception; use PHPUnit\Framework\Constraint\Exception as ConstraintException; use PHPUnit\Framework\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { const UNCHANGED_ARRAY = ["unchanged"]; static function assertException($class, callable $func, ...$args) { try { call_user_func_array($func, $args); $e = null; } catch (Exception $e) { } self::assertThat($e, new ConstraintException($class)); } static function assertNotException(callable $func, ...$args) { try { call_user_func_array($func, $args); $e = null; $message = ""; } catch (Exception $e) { $message = "L'exception ".get_class($e)." a été lancée"; } self::assertTrue($e === null, $message); } static function assertSameKeys(array $expected, array $actual) { self::assertSame($expected, array_keys($actual)); } static function assertSameValues(array $expected, array $actual) { self::assertSame($expected, array_values($actual)); } protected $origTz; /** * forcer systématiquement le timezone dans Indian/Reunion pour que les tests * de date soient corrects */ protected function setUp(): void { $this->origTz = date_default_timezone_get(); date_default_timezone_set("Indian/Reunion"); } protected function tearDown(): void { date_default_timezone_set($this->origTz); } }