Passed
Pull Request — master (#12)
by Alex
12:12
created

SystemClockTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArpTest\DateTime\Psr;
6
7
use _PHPStan_950705577\React\Http\Io\Clock;
0 ignored issues
show
Bug introduced by
The type _PHPStan_950705577\React\Http\Io\Clock was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Arp\DateTime\DateTimeImmutableFactory;
9
use Arp\DateTime\Psr\SystemClock;
10
use PHPUnit\Framework\MockObject\MockObject;
11
use PHPUnit\Framework\TestCase;
12
use Psr\Clock\ClockInterface;
13
14
/**
15
 * @covers \Arp\DateTime\Psr\SystemClock
16
 */
17
final class SystemClockTest extends TestCase
18
{
19
    /**
20
     * @var DateTimeImmutableFactory&MockObject
21
     */
22
    private DateTimeImmutableFactory $factory;
23
24
    public function setUp(): void
25
    {
26
        $this->factory = $this->createMock(DateTimeImmutableFactory::class);
27
    }
28
29
    public function testImplementsClockInterface(): void
30
    {
31
        $this->assertInstanceOf(ClockInterface::class, new SystemClock($this->factory));
32
    }
33
34
    /**
35
     * @throws \Exception
36
     */
37
    public function testNow(): void
38
    {
39
        $clock = new SystemClock($this->factory);
40
41
        $systemTimeZone = date_default_timezone_get();
42
        $dateTimeImmutable = new \DateTimeImmutable('now', new \DateTimeZone($systemTimeZone));
43
44
        $this->factory->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Arp\DateTime\DateTimeImmutableFactory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        $this->factory->/** @scrutinizer ignore-call */ 
45
                        expects($this->once())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
            ->method('createDateTime')
46
            ->with('now', $systemTimeZone)
47
            ->willReturn($dateTimeImmutable);
48
49
        $this->assertSame($dateTimeImmutable, $clock->now());
50
    }
51
}
52