Skip to content

Commit

Permalink
Add serialization and clone tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jan 23, 2015
1 parent 46502bf commit 7009ee3
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 8 deletions.
7 changes: 7 additions & 0 deletions framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php
Expand Up @@ -79,6 +79,13 @@ public function __construct($data = null)
}
}

/**
*/
public function __clone()
{
throw new LogicException('Object can not be cloned.');
}

/**
*/
public function __get($name)
Expand Down
31 changes: 31 additions & 0 deletions framework/Imap_Client/test/Horde/Imap/Client/DateTimeTest.php
Expand Up @@ -53,4 +53,35 @@ public function testDateTimeParsing($date, $expected)
);
}

public function testClone()
{
$ob = new Horde_Imap_Client_DateTime('12 Sep 2007 15:49:12 UTC');

$ob2 = clone $ob;

$ob2->modify('+1 minute');

$this->assertEquals(
1189612152,
intval(strval($ob))
);

$this->assertEquals(
1189612152 + 60,
intval(strval($ob2))
);
}

public function testSerialize()
{
$ob = new Horde_Imap_Client_DateTime('12 Sep 2007 15:49:12 UTC');

$ob2 = unserialize(serialize($ob));

$this->assertEquals(
1189612152,
intval(strval($ob2))
);
}

}
29 changes: 29 additions & 0 deletions framework/Imap_Client/test/Horde/Imap/Client/IdsTest.php
Expand Up @@ -330,4 +330,33 @@ public function sequenceStringGenerationProvider()
);
}

public function testClone()
{
$ids = new Horde_Imap_Client_Ids(array(1, 3));

$ids2 = clone $ids;
$ids2->add(5);

$this->assertEquals(
array(1, 3),
iterator_to_array($ids)
);
$this->assertEquals(
array(1, 3, 5),
iterator_to_array($ids2)
);
}

public function testSerialize()
{
$ids = new Horde_Imap_Client_Ids(array(1, 3, 5));

$ids2 = unserialize(serialize($ids));

$this->assertEquals(
array(1, 3, 5),
iterator_to_array($ids2)
);
}

}
12 changes: 12 additions & 0 deletions framework/Imap_Client/test/Horde/Imap/Client/MailboxTest.php
Expand Up @@ -25,6 +25,18 @@
*/
class Horde_Imap_Client_MailboxTest extends PHPUnit_Framework_TestCase
{
public function testMailboxClone()
{
$ob = new Horde_Imap_Client_Mailbox('Envoyé');

$ob2 = clone $ob;

$this->assertEquals(
'Envoyé',
$ob2->utf8
);
}

public function testMailboxSerialize()
{
$mailbox = unserialize(
Expand Down
38 changes: 30 additions & 8 deletions framework/Imap_Client/test/Horde/Imap/Client/MapTest.php
Expand Up @@ -94,8 +94,37 @@ public function testUpdate()
);
}

public function testCount()
{
$this->assertEquals(
6,
count($this->map)
);
}

/**
* @depends testCount
*/
public function testClone()
{
$map2 = clone $this->map;
$map2->update(array(
1 => 1
));

$this->assertEquals(
6,
count($this->map)
);
$this->assertEquals(
7,
count($map2)
);
}

/**
* @dataProvider lookupProvider
* @depends testClone
*/
public function testLookup($range, $expected = null)
{
Expand Down Expand Up @@ -134,6 +163,7 @@ public function lookupProvider()

/**
* @dataProvider removeProvider
* @depends testClone
*/
public function testRemove($range, $expected)
{
Expand Down Expand Up @@ -221,14 +251,6 @@ public function testRemoveWithDuplicateSequenceNumbers()
);
}

public function testCount()
{
$this->assertEquals(
6,
count($this->map)
);
}

public function testIterator()
{
$this->assertEquals(
Expand Down
18 changes: 18 additions & 0 deletions framework/Imap_Client/test/Horde/Imap/Client/SearchTest.php
Expand Up @@ -558,6 +558,24 @@ public function previousSearchQueryProvider()
);
}

public function testClone()
{
$ob = new Horde_Imap_Client_Search_Query();
$ob->text('foo');

$ob2 = clone $ob;
$ob2->text('bar');

$this->assertEquals(
'BODY foo',
strval($ob)
);
$this->assertEquals(
'BODY foo BODY bar',
strval($ob2)
);
}

public function testSerialize()
{
$ob = new Horde_Imap_Client_Search_Query();
Expand Down
22 changes: 22 additions & 0 deletions framework/Imap_Client/test/Horde/Imap/Client/TokenizeTest.php
Expand Up @@ -466,4 +466,26 @@ public function testLiteralLength()
);
}

/**
* @expectedException LogicException
*/
public function testClone()
{
$test = 'FOO BAR';
$token = new Horde_Imap_Client_Tokenize($test);

clone $token;
}

/**
* @expectedException LogicException
*/
public function testSerialize()
{
$test = 'FOO BAR';
$token = new Horde_Imap_Client_Tokenize($test);

serialize($token);
}

}

0 comments on commit 7009ee3

Please sign in to comment.