Skip to content

Commit

Permalink
Working on the cookie implementation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed Feb 15, 2017
1 parent de41228 commit d571324
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 7 deletions.
68 changes: 68 additions & 0 deletions tests/TestCase/Http/Cookie/CookieCollectionTest.php
@@ -0,0 +1,68 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.5.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\Http\Cookie;

use Cake\Http\Cookie\Cookie;
use Cake\Http\Cookie\CookieCollection;
use Cake\TestSuite\TestCase;

/**
* Cookie collection test.
*/
class CookieCollectionTest extends TestCase
{
/**
* Test constructor
*
* @return void
*/
public function testConstructorWithEmptyArray()
{
$collection = new CookieCollection([]);
$this->assertCount(0, $collection);
}

/**
* Test valid cookies
*
* @return void
*/
public function testConstructorWithCookieArray()
{
$cookies = [
new Cookie('one', 'one'),
new Cookie('two', 'two')
];

$collection = new CookieCollection($cookies);
$this->assertCount(2, $collection);
}

/**
* Test that the constructor takes only an array of objects implementing
* the CookieInterface
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Expected `Cake\Http\Cookie\CookieCollection[]` as $cookies but instead got `array` at index 1
* @return void
*/
public function testConstructorWithInvalidCookieObjects()
{
$array = [
new Cookie('one', 'one'),
[]
];

new CookieCollection($array);
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Http/Cookie/CookieTest.php
Expand Up @@ -7,7 +7,7 @@
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @since 3.5.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\Http\Cookie;
Expand Down
6 changes: 2 additions & 4 deletions tests/TestCase/Http/Cookie/RequestCookiesTest.php
Expand Up @@ -7,7 +7,7 @@
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @since 3.5.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\Http\Cookie;
Expand All @@ -31,9 +31,7 @@ class RequestCookiesTest extends TestCase
public $request;

/**
* setup
*
* @return null
* {@inheritDoc}
*/
public function setUp()
{
Expand Down
29 changes: 27 additions & 2 deletions tests/TestCase/Http/Cookie/ResponseCookiesTest.php
Expand Up @@ -7,19 +7,44 @@
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @since 3.5.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\TestCase\Http\Cookie;

use Cake\Http\Client\Response;
use Cake\Http\Cookie\Cookie;
use Cake\Http\Cookie\ResponseCookies;
use Cake\TestSuite\TestCase;

/**
* HTTP cookies test.
* Response Cookies Test
*/
class ResponseCookiesTest extends TestCase
{
/**
* testAddToResponse
*
* @return void
*/
public function testAddToResponse()
{
$cookies = [
new Cookie('one', 'one'),
new Cookie('two', 'two')
];

$responseCookies = new ResponseCookies($cookies);

$response = new Response();
$response = $responseCookies->addToResponse($response);

$expected = [
'Set-Cookie' => [
'one=one',
'two=two'
]
];
$this->assertEquals($expected, $response->getHeaders());
}
}

0 comments on commit d571324

Please sign in to comment.