1 | <?php |
||||||
2 | |||||||
3 | /* |
||||||
4 | * @copyright 2019 Mautic Contributors. All rights reserved |
||||||
5 | * @author Mautic, Inc. |
||||||
6 | * |
||||||
7 | * @link https://mautic.org |
||||||
8 | * |
||||||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||||||
10 | */ |
||||||
11 | |||||||
12 | namespace Mautic\CoreBundle\Tests\Unit\Templating\Helper; |
||||||
13 | |||||||
14 | use Mautic\CoreBundle\Helper\CoreParametersHelper; |
||||||
15 | use Mautic\CoreBundle\Templating\Helper\DateHelper; |
||||||
16 | use Symfony\Component\Translation\TranslatorInterface; |
||||||
17 | |||||||
18 | class DateHelperTest extends \PHPUnit\Framework\TestCase |
||||||
19 | { |
||||||
20 | /** |
||||||
21 | * @var \PHPUnit\Framework\MockObject\MockObject|TranslatorInterface |
||||||
22 | */ |
||||||
23 | private $translator; |
||||||
24 | |||||||
25 | /** |
||||||
26 | * @var DateHelper |
||||||
27 | */ |
||||||
28 | private $helper; |
||||||
29 | |||||||
30 | /** |
||||||
31 | * @var string |
||||||
32 | */ |
||||||
33 | private static $oldTimezone; |
||||||
34 | |||||||
35 | /** |
||||||
36 | * @var CoreParametersHelper|\PHPUnit\Framework\MockObject\MockObject |
||||||
37 | */ |
||||||
38 | private $coreParametersHelper; |
||||||
39 | |||||||
40 | public static function setUpBeforeClass(): void |
||||||
41 | { |
||||||
42 | self::$oldTimezone = date_default_timezone_get(); |
||||||
43 | } |
||||||
44 | |||||||
45 | public static function tearDownAfterClass(): void |
||||||
46 | { |
||||||
47 | date_default_timezone_set(self::$oldTimezone); |
||||||
48 | } |
||||||
49 | |||||||
50 | protected function setUp(): void |
||||||
51 | { |
||||||
52 | $this->translator = $this->createMock(TranslatorInterface::class); |
||||||
53 | $this->coreParametersHelper = $this->createMock(CoreParametersHelper::class); |
||||||
54 | $this->helper = new DateHelper( |
||||||
55 | 'F j, Y g:i a T', |
||||||
56 | 'D, M d', |
||||||
57 | 'F j, Y', |
||||||
58 | 'g:i a', |
||||||
59 | $this->translator, |
||||||
60 | $this->coreParametersHelper |
||||||
61 | ); |
||||||
62 | } |
||||||
63 | |||||||
64 | public function testStringToText() |
||||||
65 | { |
||||||
66 | date_default_timezone_set('Etc/GMT-4'); |
||||||
67 | $time = '2016-01-27 14:30:00'; |
||||||
68 | $this->assertSame('January 27, 2016 6:30 pm', $this->helper->toText($time, 'UTC', 'Y-m-d H:i:s', true)); |
||||||
69 | } |
||||||
70 | |||||||
71 | public function testStringToTextUtc() |
||||||
72 | { |
||||||
73 | date_default_timezone_set('UTC'); |
||||||
74 | $time = '2016-01-27 14:30:00'; |
||||||
75 | |||||||
76 | $this->assertSame('January 27, 2016 2:30 pm', $this->helper->toText($time, 'UTC', 'Y-m-d H:i:s', true)); |
||||||
77 | } |
||||||
78 | |||||||
79 | public function testDateTimeToText() |
||||||
80 | { |
||||||
81 | date_default_timezone_set('Etc/GMT-4'); |
||||||
82 | $dateTime = new \DateTime('2016-01-27 14:30:00', new \DateTimeZone('UTC')); |
||||||
83 | $this->assertSame('January 27, 2016 6:30 pm', $this->helper->toText($dateTime, 'UTC', 'Y-m-d H:i:s', true)); |
||||||
84 | } |
||||||
85 | |||||||
86 | public function testDateTimeToTextUtc() |
||||||
87 | { |
||||||
88 | date_default_timezone_set('UTC'); |
||||||
89 | $dateTime = new \DateTime('2016-01-27 14:30:00', new \DateTimeZone('UTC')); |
||||||
90 | |||||||
91 | $this->assertSame('January 27, 2016 2:30 pm', $this->helper->toText($dateTime, 'UTC', 'Y-m-d H:i:s', true)); |
||||||
92 | } |
||||||
93 | |||||||
94 | public function testToTextWithConfigurationToTime() |
||||||
95 | { |
||||||
96 | $this->coreParametersHelper->method('get') |
||||||
0 ignored issues
–
show
|
|||||||
97 | ->with('date_format_timeonly') |
||||||
98 | ->willReturn('00:00:00'); |
||||||
99 | |||||||
100 | $this->translator->method('trans') |
||||||
0 ignored issues
–
show
The method
method() does not exist on Symfony\Component\Translation\TranslatorInterface . It seems like you code against a sub-type of Symfony\Component\Translation\TranslatorInterface such as Symfony\Component\Transl...DataCollectorTranslator or Symfony\Component\Translation\LoggingTranslator .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
101 | ->willReturnCallback( |
||||||
102 | function (string $key, array $parameters = []) { |
||||||
103 | if (isset($parameters['%time%'])) { |
||||||
104 | return $parameters['%time%']; |
||||||
105 | } |
||||||
106 | } |
||||||
107 | ); |
||||||
108 | |||||||
109 | $dateTime = new \DateTime('now', new \DateTimeZone('UTC')); |
||||||
110 | |||||||
111 | $this->assertSame('00:00:00', $this->helper->toText($dateTime)); |
||||||
112 | } |
||||||
113 | } |
||||||
114 |
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.