|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Happyr Doctrine Specification package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Tobias Nyholm <[email protected]> |
|
7
|
|
|
* Kacper Gunia <[email protected]> |
|
8
|
|
|
* Peter Gribanov <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace tests\Happyr\DoctrineSpecification\Result; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use Doctrine\ORM\AbstractQuery; |
|
18
|
|
|
use Doctrine\ORM\Query\Parameter; |
|
19
|
|
|
use Happyr\DoctrineSpecification\Result\RoundDateTime; |
|
20
|
|
|
use PhpSpec\ObjectBehavior; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @mixin RoundDateTime |
|
24
|
|
|
*/ |
|
25
|
|
|
class RoundDateTimeSpec extends ObjectBehavior |
|
26
|
|
|
{ |
|
27
|
|
|
private $roundSeconds = 3600; |
|
28
|
|
|
|
|
29
|
|
|
public function let() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->beConstructedWith($this->roundSeconds); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function it_is_a_specification() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->shouldBeAnInstanceOf(RoundDateTime::class); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function it_round_date_time_in_query_parameters_for_given_time(AbstractQuery $query) |
|
40
|
|
|
{ |
|
41
|
|
|
$name = 'now'; |
|
42
|
|
|
$type = 'datetime'; |
|
43
|
|
|
$actual = new \DateTime('15:55:34'); |
|
44
|
|
|
$expected = new \DateTimeImmutable('15:00:00'); |
|
45
|
|
|
|
|
46
|
|
|
if (class_exists(Parameter::class)) { // doctrine/orm >= 2.3 |
|
47
|
|
|
$query->getParameters()->willReturn(new ArrayCollection([ |
|
48
|
|
|
new Parameter('status', 'active'), // scalar param |
|
49
|
|
|
new Parameter($name, $actual, $type), |
|
50
|
|
|
])); |
|
51
|
|
|
$query->setParameter($name, $expected, $type)->shouldBeCalled(); |
|
52
|
|
|
} else { |
|
53
|
|
|
$query->getParameters()->willReturn([ |
|
54
|
|
|
'status' => 'active', // scalar param |
|
55
|
|
|
$name => $actual, |
|
56
|
|
|
]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$this->modify($query); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|