Re: Problem with Session and PHP Unit Test

2015-01-22 Thread monica
Thank you Mark ;) but it haven't solved the problem.

I've tried couple of times to use it ($this->session). 
My first attempt:

public function testResetFilters() {
  $this->session([
   'WhatIsInside' => 'littlebunny',
   'CurrentFilter' => 'this is the filter'
  ]);
  $expected_filter = 'this is the filter';
  $this->assertSession($expected_filter, 
'CurrentFilter');
}

but still test failed.

I tried also to read from session:

public function testResetFilters() {
  $this->session([
   'WhatIsInside' => 'littlebunny',
   'CurrentFilter' => 'this is the filter'
  ]);
  $oldUserSession = $this->session(['CurrentFilter']);
  
  $this->assertSession($oldUserSession, 
'CurrentFilter');
}

But this one also failed. 

Am I using properly assertSession()?
How to read from the session when you are writing to it using 
$this->session()?




On Wednesday, 21 January 2015 15:23:12 UTC, euromark wrote:
>
> in 3.x the --stderr of course is not necessary anymore
>
> For 3.x please use the IntegrationTest as it is designed, so add
>
> $this->session($data), instead of actually writing to the session.
>
> Mark
>
>
>
> Am Mittwoch, 21. Januar 2015 12:49:17 UTC+1 schrieb monica:
>>
>> Thanks mark for tip ;)
>>
>> I've checked with that option and nothing really changed. I forgot to 
>> mention it's cakephp 3.0.
>> This is the command I'm running:
>>
>> php phpunit.phar --stderr -v tests/TestCase/Controller/
>> UnitTestsControllerTest.php
>>
>>
>>
>>
>>
>> On Tuesday, 20 January 2015 18:58:47 UTC, euromark wrote:
>>>
>>> Dont forget --stderr when testing 2.x tests in CLI
>>>
>>> mark
>>>
>>>
>>> Am Dienstag, 20. Januar 2015 13:29:47 UTC+1 schrieb monica:
>>>>
>>>> Hi!
>>>>
>>>> I baked new UnitTestsController for testing purposes and put inside the 
>>>> function:
>>>>
>>>>
>>>> public function reset_filters() {
>>>>  // suppose to delete CurrentFilter var from session
>>>>  this->request->session()->delete('CurrentFilter');
>>>> }
>>>>
>>>>
>>>> I wanted to test session so I baked also UnitTestsControllerTest.php 
>>>>
>>>> public function testResetFilters() {
>>>>  $session = new Session;
>>>>  
>>>>  $session->write([
>>>> 'WhatIsInside' => 'littlebunny',
>>>> 'CurrentFilter' => 'this is the filter'
>>>> ]);
>>>>  
>>>>  // saving one of session vars
>>>>  $oldUserSession = $session->read('WhatIsInside');
>>>>  
>>>>  // calling function which suppose to delete the other session 
>>>> var (CurrentFilter) and leave WhatIsInside session var untouched
>>>>  $this->get('/UnitTests/reset_filters');
>>>>  
>>>>  // getting that other var from session
>>>>  $newUserSession = $session->read('WhatIsInside');
>>>>
>>>>  // checking if function hasn't deleted the other session vars
>>>>  $this->assertSame($oldUserSession, $newUserSession);
>>>> }
>>>>
>>>>
>>>> But the test *failed*. 
>>>>
>>>> I printed content of both sessions data before and after function.
>>>> Before function is giving me correct output but after calling the 
>>>> function it's giving me null.
>>>>
>>>> Console output:
>>>>
>>>>
>>>> There was 1 failure:
>>>>
>>>> 1) 
>>>> App\Test\TestCase\Controller\UnitTestsControllerTest::testResetFilters
>>>> Failed asserting that null is identical to 'littlebunny'.
>>>>
>>>>
>>>>
>>>> I don't what I did wrong and any help will be appreciated. 
>>>>
>>>>
-- 


*** CONFIDENTIALITY NOTICE AND

Re: Problem with Session and PHP Unit Test

2015-01-21 Thread monica
Thanks mark for tip ;)

I've checked with that option and nothing really changed. I forgot to 
mention it's cakephp 3.0.
This is the command I'm running:

php phpunit.phar --stderr -v tests/TestCase/Controller/
UnitTestsControllerTest.php





On Tuesday, 20 January 2015 18:58:47 UTC, euromark wrote:
>
> Dont forget --stderr when testing 2.x tests in CLI
>
> mark
>
>
> Am Dienstag, 20. Januar 2015 13:29:47 UTC+1 schrieb monica:
>>
>> Hi!
>>
>> I baked new UnitTestsController for testing purposes and put inside the 
>> function:
>>
>>
>> public function reset_filters() {
>>  // suppose to delete CurrentFilter var from session
>>  this->request->session()->delete('CurrentFilter');
>> }
>>
>>
>> I wanted to test session so I baked also UnitTestsControllerTest.php 
>>
>> public function testResetFilters() {
>>  $session = new Session;
>>  
>>  $session->write([
>> 'WhatIsInside' => 'littlebunny',
>> 'CurrentFilter' => 'this is the filter'
>> ]);
>>  
>>  // saving one of session vars
>>  $oldUserSession = $session->read('WhatIsInside');
>>  
>>  // calling function which suppose to delete the other session 
>> var (CurrentFilter) and leave WhatIsInside session var untouched
>>  $this->get('/UnitTests/reset_filters');
>>  
>>  // getting that other var from session
>>  $newUserSession = $session->read('WhatIsInside');
>>
>>  // checking if function hasn't deleted the other session vars
>>  $this->assertSame($oldUserSession, $newUserSession);
>> }
>>
>>
>> But the test *failed*. 
>>
>> I printed content of both sessions data before and after function.
>> Before function is giving me correct output but after calling the 
>> function it's giving me null.
>>
>> Console output:
>>
>>
>> There was 1 failure:
>>
>> 1) App\Test\TestCase\Controller\UnitTestsControllerTest::testResetFilters
>> Failed asserting that null is identical to 'littlebunny'.
>>
>>
>>
>> I don't what I did wrong and any help will be appreciated. 
>>
>>
-- 


*** CONFIDENTIALITY NOTICE AND LEGAL LIABILITY WAIVER ***

The content of this email and any attachments are CONFIDENTIAL and may 
contain privileged information. If you are not the addressee it may be 
UNLAWFUL for you to read, copy, distribute or disclose the information 
contained herein. This email and any attachments may not reflect the 
opinions of the originating company or any party it is representing. 
Telephone calls may be recorded for training and quality monitoring 
purposes.

The Car Finance Company (2007) Ltd Registered Address is 47-51 Kingston 
Crescent, Portsmouth, PO2 8AA and is authorised and regulated by the 
Financial Conduct Authority, CCL number 600168. 

The Car Finance Company (Trade Sales) Ltd is a wholly owned subsidiary of 
The Car Finance Company (2007) Ltd. Registered Address is 47-51 Kingston 
Crescent, Portsmouth, PO2 8AA and is authorised and regulated by the 
Financial Conduct Authority, CCL number 663690.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Problem with Session and PHP Unit Test

2015-01-20 Thread monica
Hi!

I baked new UnitTestsController for testing purposes and put inside the 
function:


public function reset_filters() {
 // suppose to delete CurrentFilter var from session
 this->request->session()->delete('CurrentFilter');
}


I wanted to test session so I baked also UnitTestsControllerTest.php 

public function testResetFilters() {
 $session = new Session;
 
 $session->write([
'WhatIsInside' => 'littlebunny',
'CurrentFilter' => 'this is the filter'
]);
 
 // saving one of session vars
 $oldUserSession = $session->read('WhatIsInside');
 
 // calling function which suppose to delete the other session var 
(CurrentFilter) and leave WhatIsInside session var untouched
 $this->get('/UnitTests/reset_filters');
 
 // getting that other var from session
 $newUserSession = $session->read('WhatIsInside');

 // checking if function hasn't deleted the other session vars
 $this->assertSame($oldUserSession, $newUserSession);
}


But the test *failed*. 

I printed content of both sessions data before and after function.
Before function is giving me correct output but after calling the function 
it's giving me null.

Console output:


There was 1 failure:

1) App\Test\TestCase\Controller\UnitTestsControllerTest::testResetFilters
Failed asserting that null is identical to 'littlebunny'.



I don't what I did wrong and any help will be appreciated. 




-- 


*** CONFIDENTIALITY NOTICE AND LEGAL LIABILITY WAIVER ***

The content of this email and any attachments are CONFIDENTIAL and may 
contain privileged information. If you are not the addressee it may be 
UNLAWFUL for you to read, copy, distribute or disclose the information 
contained herein. This email and any attachments may not reflect the 
opinions of the originating company or any party it is representing. 
Telephone calls may be recorded for training and quality monitoring 
purposes.

The Car Finance Company (2007) Ltd Registered Address is 47-51 Kingston 
Crescent, Portsmouth, PO2 8AA and is authorised and regulated by the 
Financial Conduct Authority, CCL number 600168. 

The Car Finance Company (Trade Sales) Ltd is a wholly owned subsidiary of 
The Car Finance Company (2007) Ltd. Registered Address is 47-51 Kingston 
Crescent, Portsmouth, PO2 8AA and is authorised and regulated by the 
Financial Conduct Authority, CCL number 663690.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.