<?php

namespace Tests;

use Rosio\EncryptedCookie;
use Rosio\EncryptedCookie\CookieFactory;
use Rosio\EncryptedCookie\CryptoSystem\AES_SHA1;

class CookieFactoryTest extends \PHPUnit_Framework_TestCase
{
	public function testEncryptDecrypt ()
	{
		$this->markTestIncomplete('Need to find workaround so as to not try and actually set a cookie.');

		$factory = new CookieFactory(new AES_SHA1('symtest', 'hmactest'));

		$data = 'blah';

		$cookie = $factory->create('testCookie')->setData($data)->save();

		$newCookie = $factory->get('testCookie');

		$this->assertEquals($data, $newCookie->getData());
	}
}
<?php

namespace Tests;

use Mockery as m;

use Rosio\EncryptedCookie;
use Rosio\EncryptedCookie\CookieFactory;
use Rosio\EncryptedCookie\CryptoSystem\AES_SHA1;

class CookieFactoryTest extends \PHPUnit_Framework_TestCase
{
	public function tearDown ()
	{
		m::close();
	}

	public function testEncryptDecrypt ()
	{
		$storage = m::mock('\Rosio\EncryptedCookie\CookieStorage');
		$storage->shouldReceive('set')->once()->with(m::type('\Rosio\EncryptedCookie\EncryptedCookie'));
		$storage->shouldReceive('has')->once()->andReturn(true);
		$storage->shouldReceive('get')->once()->andReturn('blah');

		$factory = new CookieFactory(new AES_SHA1('symtest', 'hmactest'), $storage);

		$data = 'blah';

		$cookie = $factory->create('testCookie')->setData($data)->save();

		$newCookie = $factory->get('testCookie');

		// Returned data wasn't the correctly encrypted data, so it should fail to decrypt it
		$this->assertFalse($newCookie->getData());
	}
}
Test the factory a bit
Test the factory a bit
