|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Clock\Tests; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Psr\Clock\ClockInterface; |
| 16 | +use Symfony\Component\Clock\Clock; |
| 17 | +use Symfony\Component\Clock\MockClock; |
| 18 | +use Symfony\Component\Clock\NativeClock; |
| 19 | +use Symfony\Component\Clock\Test\ClockSensitiveTrait; |
| 20 | + |
| 21 | +class ClockBeforeClassTest extends TestCase |
| 22 | +{ |
| 23 | + use ClockSensitiveTrait; |
| 24 | + |
| 25 | + private static ?ClockInterface $clock = null; |
| 26 | + |
| 27 | + public static function setUpBeforeClass(): void |
| 28 | + { |
| 29 | + self::$clock = self::mockTime(); |
| 30 | + } |
| 31 | + |
| 32 | + public static function tearDownAfterClass(): void |
| 33 | + { |
| 34 | + self::$clock = null; |
| 35 | + } |
| 36 | + |
| 37 | + public function testMockClock() |
| 38 | + { |
| 39 | + $this->assertInstanceOf(MockClock::class, self::$clock); |
| 40 | + $this->assertInstanceOf(NativeClock::class, Clock::get()); |
| 41 | + |
| 42 | + $clock = self::mockTime(); |
| 43 | + $this->assertInstanceOf(MockClock::class, Clock::get()); |
| 44 | + $this->assertSame(Clock::get(), $clock); |
| 45 | + |
| 46 | + $this->assertNotSame($clock, self::$clock); |
| 47 | + |
| 48 | + self::restoreClockAfterTest(); |
| 49 | + self::saveClockBeforeTest(); |
| 50 | + |
| 51 | + $this->assertInstanceOf(MockClock::class, self::$clock); |
| 52 | + $this->assertInstanceOf(NativeClock::class, Clock::get()); |
| 53 | + |
| 54 | + $clock = self::mockTime(); |
| 55 | + $this->assertInstanceOf(MockClock::class, Clock::get()); |
| 56 | + $this->assertSame(Clock::get(), $clock); |
| 57 | + |
| 58 | + $this->assertNotSame($clock, self::$clock); |
| 59 | + } |
| 60 | +} |
0 commit comments