Re: What is the proper way of testing controllers in CakePHP 2.0
Did you ever figure this out? My $this->header is always returning an empty array an empty array as well, I've been stuck on this for a couple days now.. Please help me if you figured this out On Thursday, August 25, 2011 12:33:08 AM UTC-5, Christophe Roblin wrote: > > No, $this->headers seems to always return an empty array > > On 25 Aug, 06:02, jeremyharris wrote: > > When you debug the $this->headers var, what do you get back? Anything > > at all? > > > > If you're not getting anything back then it might be a problem with > > testAction, although there are tests that show it works. > > > > On Aug 21, 1:48 am, Christophe Roblin wrote: > > > > > > > > > > > > > > > > > Hi, > > > > > I've tried searching the new docs about testing with the new PHPUnit > > > for CakePHP 2.0 Beta, without any success > > > Below is my code for testing the admin action of controller posts with > > > method add. > > > > > My issue is that I expected from the docs I received that headers were > > > set when using testAction, it is always blank > > > > > public function testAdminAdd() { > > > $Posts = $this->generate('Posts', array( > > > 'components' => array( > > > 'Session' > > > ) > > > ) > > > ); > > > > > $Posts->Session->expects($this->once())- > > > > > >method('setFlash'); > > > > > $this->testAction('/admin/posts/add', array( > > > 'data' => array( > > > 'Post' => array('name' => 'New Post') > > > ) > > > ) > > > ); > > >// debug($this); > > > $this->assertEquals($this->headers['Location'], '/admin/ > > > posts/index'); > > > $this->assertEquals($this->vars['post']['Post']['name'], > > > 'New Post'); > > > > > $this->assertPattern('/contents); > > > $this->assertPattern('/view); -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: What is the proper way of testing controllers in CakePHP 2.0
No, $this->headers seems to always return an empty array On 25 Aug, 06:02, jeremyharris wrote: > When you debug the $this->headers var, what do you get back? Anything > at all? > > If you're not getting anything back then it might be a problem with > testAction, although there are tests that show it works. > > On Aug 21, 1:48 am, Christophe Roblin wrote: > > > > > > > > > Hi, > > > I've tried searching the new docs about testing with the new PHPUnit > > for CakePHP 2.0 Beta, without any success > > Below is my code for testing the admin action of controller posts with > > method add. > > > My issue is that I expected from the docs I received that headers were > > set when using testAction, it is always blank > > > public function testAdminAdd() { > > $Posts = $this->generate('Posts', array( > > 'components' => array( > > 'Session' > > ) > > ) > > ); > > > $Posts->Session->expects($this->once())- > > > >method('setFlash'); > > > $this->testAction('/admin/posts/add', array( > > 'data' => array( > > 'Post' => array('name' => 'New Post') > > ) > > ) > > ); > > // debug($this); > > $this->assertEquals($this->headers['Location'], '/admin/ > > posts/index'); > > $this->assertEquals($this->vars['post']['Post']['name'], > > 'New Post'); > > > $this->assertPattern('/contents); > > $this->assertPattern('/view); -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: What is the proper way of testing controllers in CakePHP 2.0
When you debug the $this->headers var, what do you get back? Anything at all? If you're not getting anything back then it might be a problem with testAction, although there are tests that show it works. On Aug 21, 1:48 am, Christophe Roblin wrote: > Hi, > > I've tried searching the new docs about testing with the new PHPUnit > for CakePHP 2.0 Beta, without any success > Below is my code for testing the admin action of controller posts with > method add. > > My issue is that I expected from the docs I received that headers were > set when using testAction, it is always blank > > public function testAdminAdd() { > $Posts = $this->generate('Posts', array( > 'components' => array( > 'Session' > ) > ) > ); > > $Posts->Session->expects($this->once())- > > >method('setFlash'); > > $this->testAction('/admin/posts/add', array( > 'data' => array( > 'Post' => array('name' => 'New Post') > ) > ) > ); > // debug($this); > $this->assertEquals($this->headers['Location'], '/admin/ > posts/index'); > $this->assertEquals($this->vars['post']['Post']['name'], > 'New Post'); > > $this->assertPattern('/contents); > $this->assertPattern('/view); -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: What is the proper way of testing controllers in CakePHP 2.0
In order to test the result of the complete request cycle you need to use the second parameter of testAction as follows : $this->testAction(('/admin/posts/add', array('return' => false)) This way you will be able to assert headers, and text from the layout, the other possible value for 'return' key is 'result', which is the default for the function. I will try to document this a bit better today. Thanks! -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
What is the proper way of testing controllers in CakePHP 2.0
Hi, I've tried searching the new docs about testing with the new PHPUnit for CakePHP 2.0 Beta, without any success Below is my code for testing the admin action of controller posts with method add. My issue is that I expected from the docs I received that headers were set when using testAction, it is always blank public function testAdminAdd() { $Posts = $this->generate('Posts', array( 'components' => array( 'Session' ) ) ); $Posts->Session->expects($this->once())- >method('setFlash'); $this->testAction('/admin/posts/add', array( 'data' => array( 'Post' => array('name' => 'New Post') ) ) ); // debug($this); $this->assertEquals($this->headers['Location'], '/admin/ posts/index'); $this->assertEquals($this->vars['post']['Post']['name'], 'New Post'); $this->assertPattern('/contents); $this->assertPattern('/view); -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php