Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Merge 5650fe2 into 2efb8c3
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Oct 5, 2019
2 parents 2efb8c3 + 5650fe2 commit df8bf75
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions phpunit.xml.dist
Expand Up @@ -20,5 +20,6 @@
</filter>
<php>
<env name="CDEK_BASE_URL" value="http://integration.edu.cdek.ru" />
<ini name="date.timezone" value="UTC"/>
</php>
</phpunit>
10 changes: 9 additions & 1 deletion src/CdekClient.php
Expand Up @@ -145,6 +145,7 @@ private static function getVersion(): string
return "{$parts[2]}-{$parts[1]}{$parts[3]}";
}

/** @phan-suppress-next-line PhanTypeArraySuspiciousNullable */
return (string) @\json_decode((string) \file_get_contents(__DIR__.'/../composer.json'), true)['extra']['branch-alias']['dev-master'];
}

Expand Down Expand Up @@ -254,9 +255,16 @@ private function serialize(XmlRequest $request): string
// @codeCoverageIgnoreEnd
}

/**
* @see \CdekSDK\Requests\Concerns\Authorized::$date
*
* @param \DateTimeInterface $date
*
* @return string
*/
private function getSecure(\DateTimeInterface $date): string
{
return \md5($date->format('Y-m-d')."&{$this->password}");
return \md5($date->format('Y-m-d\TH:i:sP')."&{$this->password}");
}

private function hasAttachment(ResponseInterface $response): bool
Expand Down
6 changes: 5 additions & 1 deletion src/Requests/Concerns/Authorized.php
Expand Up @@ -34,9 +34,13 @@
trait Authorized
{
/**
* Дата и время в формате ISO 8601:2004: YYYY-MM-DDThh:mm:ss+hh:mm.
*
* @see \CdekSDK\CdekClient::getSecure();
*
* @JMS\XmlAttribute
* @JMS\SerializedName("Date")
* @JMS\Type("DateTimeImmutable<'Y-m-d'>")
* @JMS\Type("DateTimeImmutable<'Y-m-d\TH:i:sP'>")
*
* @var \DateTimeInterface
*
Expand Down
6 changes: 3 additions & 3 deletions tests/CdekClientTest.php
Expand Up @@ -295,7 +295,7 @@ public function credentials(string $account, string $secure): ShouldAuthorize
$client = new CdekClient('f62dcb094cc91617def72d9c260b4483', '6bd3937dcebd15beb25278bc0657014c');
$client->sendRequest($request, new \DateTime('2016-10-31'));
} catch (\LogicException $e) {
$this->assertSame('9e38e10f9d5394a033a5609c359ecaf2', $e->getMessage());
$this->assertSame('4368247f1ff152d273a29fac6993a94a', $e->getMessage());
}
}

Expand Down Expand Up @@ -425,7 +425,7 @@ public function credentials(string $account, string $secure): ShouldAuthorize
$this->assertArrayHasKey('form_params', $this->lastRequestOptions);
$this->assertSame('2018-10-13', $this->lastRequestOptions['form_params']['date']);
$this->assertSame('foo', $this->lastRequestOptions['form_params']['account']);
$this->assertSame('74938bff7e92a0cb141d94fe6da88b6b', $this->lastRequestOptions['form_params']['secure']);
$this->assertSame('d7fe9d0ad9901440c4cba573cfc0c86e', $this->lastRequestOptions['form_params']['secure']);
}

public function test_it_loads_date_from_capable_request()
Expand Down Expand Up @@ -485,7 +485,7 @@ public function getRequestDate(): \DateTimeInterface
$this->assertArrayHasKey('form_params', $this->lastRequestOptions);
$this->assertSame('2019-04-08', $this->lastRequestOptions['form_params']['date']);
$this->assertSame('foo', $this->lastRequestOptions['form_params']['account']);
$this->assertSame('522ce91d76c09e7d888406cfbd18cab1', $this->lastRequestOptions['form_params']['secure']);
$this->assertSame('161313c50e420e3ba9231ec75fbac139', $this->lastRequestOptions['form_params']['secure']);
}

public function test_client_rejects_contract_numbers()
Expand Down
16 changes: 16 additions & 0 deletions tests/Serialization/DeliveryRequestTest.php
Expand Up @@ -325,6 +325,22 @@ public function test_with_developer_key()

$this->assertSameAsXML('<?xml version="1.0" encoding="UTF-8"?>
<DeliveryRequest OrderCount="0" DeveloperKey="abcdefd4621d373cade4e832627b123" Number="888"/>
', $request);
}

public function test_with_full_date()
{
$request = DeliveryRequest::create([
'Number' => '12345',
]);

$date = new \DateTime('2012-12-21T11:49:49+0000');
$date->setTimezone(new \DateTimeZone('Europe/Moscow'));

$request->date($date);

$this->assertSameAsXML('<?xml version="1.0" encoding="UTF-8"?>
<DeliveryRequest OrderCount="0" Number="12345" Date="2012-12-21T15:49:49+04:00"/>
', $request);
}
}
2 changes: 1 addition & 1 deletion tests/Serialization/PreAlertRequestTest.php
Expand Up @@ -53,7 +53,7 @@ public function test_can_serialize()
]));

$this->assertSameAsXML('<?xml version="1.0" encoding="UTF-8"?>
<PreAlert OrderCount="2" Date="2017-09-29" Account="123" Secure="456" PvzCode="NSK333" PlannedMeetingDate="2017-10-12">
<PreAlert OrderCount="2" Date="2017-09-29T00:00:00+00:00" Account="123" Secure="456" PvzCode="NSK333" PlannedMeetingDate="2017-10-12">
<Order DispatchNumber="bar"/>
<Order Number="foo"/>
</PreAlert>
Expand Down

0 comments on commit df8bf75

Please sign in to comment.