mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Fix type error when creating tags (#501)
* Fix fatal error due to not using DateTime instead of string when creating a tag. * Add unit tests to prove tag creation. * Add unit tests to prove tag creation. * Add first seen and last seen accessors to tags, and unit tests to prove correctness.
This commit is contained in:
parent
bec1da39aa
commit
1f5bd4200d
@ -52,7 +52,7 @@ class Tag
|
|||||||
*/
|
*/
|
||||||
public static function create(array $data)
|
public static function create(array $data)
|
||||||
{
|
{
|
||||||
return new self($data['tag'], $data['description'], $data['first-seen'], $data['last-seen']);
|
return new self($data['tag'], $data['description'], new \DateTime($data['first-seen']), new \DateTime($data['last-seen']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,4 +70,20 @@ class Tag
|
|||||||
{
|
{
|
||||||
return $this->description;
|
return $this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \DateTime
|
||||||
|
*/
|
||||||
|
public function getFirstSeen()
|
||||||
|
{
|
||||||
|
return $this->firstSeen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \DateTime
|
||||||
|
*/
|
||||||
|
public function getLastSeen()
|
||||||
|
{
|
||||||
|
return $this->lastSeen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
36
tests/Model/Tag/TagTest.php
Normal file
36
tests/Model/Tag/TagTest.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Model\Tag;
|
||||||
|
|
||||||
|
use Mailgun\Model\Tag\Tag as TagModel;
|
||||||
|
use Mailgun\Tests\Model\BaseModelTest;
|
||||||
|
|
||||||
|
class TagTest extends BaseModelTest
|
||||||
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$expectedTag = 'foo';
|
||||||
|
$expectedDescription = 'bar';
|
||||||
|
$expectedFirstSeen = '2018-12-13T05:00:00Z';
|
||||||
|
$expectedLastSeeen = '2018-12-13T12:00:00Z';
|
||||||
|
$tag = TagModel::create([
|
||||||
|
'tag' => $expectedTag,
|
||||||
|
'description' => $expectedDescription,
|
||||||
|
'first-seen' => $expectedFirstSeen,
|
||||||
|
'last-seen' => $expectedLastSeeen,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(TagModel::class, $tag);
|
||||||
|
$this->assertSame($expectedTag, $tag->getTag());
|
||||||
|
$this->assertSame($expectedDescription, $tag->getDescription());
|
||||||
|
$this->assertEquals($expectedFirstSeen, $tag->getFirstSeen()->format('Y-m-d\TH:i:s\Z'));
|
||||||
|
$this->assertEquals($expectedLastSeeen, $tag->getLastSeen()->format('Y-m-d\TH:i:s\Z'));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user