for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Bouncer package.
*
* (c) François Hodierne <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Bouncer;
class ContextTest extends \PHPUnit_Framework_TestCase
{
public function testString()
$bouncer = new Bouncer();
$bouncer->addContext('key', 'value');
'value'
string
array
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
$context = $bouncer->getContext();
$this->assertEquals($context['key'], 'value');
$bouncer->addContext('key', 'newvalue');
'newvalue'
$this->assertEquals($context['key'], 'newvalue');
}
public function testArray()
$bouncer->addContext('key', array('property' => 'value', 'property2' => 'value2'));
$this->assertEquals($context['key']['property'], 'value');
$bouncer->addContext('key', array('property' => 'newvalue'));
$this->assertEquals($context['key']['property'], 'newvalue');
$this->assertEquals($context['key']['property2'], 'value2');
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: