Closed Tilogorn closed 4 years ago
@Tilogorn
$this->request()
returns view (echo
ed strings).
If you want to do unit testing: https://github.com/kenjis/ci-phpunit-test/blob/master/docs/FunctionAndClassReference.md#unittestcasenewcontrollerclassname
Thanks a lot @kenjis! That document is a huge addition of your framework I didn't even know about.
Updated test file:
<?php
class Welcome_test extends UnitTestCase
{
public function test_getSolution()
{
$controller = $this->newController('Welcome');
$actual = $controller->getSolution();
$this->assertEquals(42, $actual);
}
}
Assuming I have a controller like this:
If I would like to test
getSolution()
in a classical unit testing behaviour, I would call the method directly:Unfortunately (understandably),
$testSolution
is alwaysnull
as it seems to contain only output. Proof: If Iecho "something";
ingetSolution()
,$testSolution
equals"something"
.So is there a way to test controller methods directly that are no route methods but simple helper methods that return something?
Or do I have to change my design to define such methods in libraries/helpers?