Skip to content

Instantly share code, notes, and snippets.

@Rayne
Created May 23, 2015 11:07
Show Gist options
  • Save Rayne/5afcf404d334465850db to your computer and use it in GitHub Desktop.
Save Rayne/5afcf404d334465850db to your computer and use it in GitHub Desktop.
Basic FatFreeFramework/Base->mock() + PHPUnit example
<?php
class F3PHPUnitTest extends PHPUnit_Framework_TestCase {
public function test() {
$f3 = Base::instance();
// Don't write to STDOUT
$f3->set('QUIET', true);
$f3->route('GET /path', function(){ echo 'TEXT'; });
$this->assertNull($f3->mock('GET /path'));
$this->assertSame('TEXT', $f3->get('RESPONSE'));
}
}
@Rayne
Copy link
Author

Rayne commented Jun 2, 2017

More details and another example are available at: Unit Testing with Fat-Free-Framework

@slavensaka
Copy link

I'm having trouble mocking a Controller route
$f3->route('GET /epr/reports/aspectslug/sales', '\controllers\epr\ReportController->index');
mocking this route give a 404
$f3->mock('GET /epr/reports/aspectslug/sales');
This is an example.
could it be the path of the controller that not correct "\controllers\epr\ReportController->index"

@Rayne
Copy link
Author

Rayne commented Nov 6, 2019

It is indeed possible that the controller's path or file name is wrong. Double check your AUTOLOAD and - if used - Composer configuration. Join us on Slack to tackle your problem.

@born-kes
Copy link

born-kes commented May 4, 2020

Hello,
I have a problem with mock and phpunit

when I use base->mock() Assertion did not work $this->expectOutputString.
look here https://stackoverflow.com/questions/61594665/how-to-use-expectoutputstring-phpunits/61594808#61594808

For the record, this is not the whole problem, I hope it's not problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment