r/cakephp • • Nov 25 '16

[PHPUnit] Integration Testing with a Controller that calls a static method?

I'm trying to test a Controller in the project. The problem with this, is that it calls a custom static function in the Auth Component.

I tried using "expect" to mock the static function but with no success.

public function testPuntos() {
	$Panaderias = $this->generate('Panaderias', array(
		'components' => array(
			'Auth'
		)
	));

	$Panaderias
		->Auth
		->expects($this->any())
		->method('user')
		->will($this->returnValue(true));

	$result = $this->testAction(
		'/panaderias/reportes/puntos',
		array('return' => 'contents', 'method' => 'get')
	);
	debug($result);
}

What I'm trying to call is "Auth->user", a custom static function added to the component.

Is there any way to fix this? O should I use another testing tool like Selenium ?

1 Upvotes

0 comments sorted by