FireTest 2.2.0 Released – Adding Mocking Capabilities

https://github.com/ua1-labs/firetest/tree/2.2.0

Exciting news from UA1 Labs! We just release FireTest 2.2.0. In this release we added the ability to request mocked objects from within Test Cases. We found that when we were writing tests for FireSql, that we wanted to have the ability to mock PDO so that we didn’t have to worry about actual interactions with the database. But we found that using FireDi, that we were still a bit far from the goal of unit testing our FireSql project without having the ability to mock.

Keeping our end goal in mind of simplicity within our testing, we wanted to make sure we exposed just enough functionality to make this new feature functional, but not overcomplicate the process of getting a mocked object.

<?php
use \UA1Labs\Fire\Test\TestCase;

class MyTestCase extends TestCase 
{
    testMyFirstTest()
    {
        $mock = $this->getMockObject(MyClass::class);
    }
} 

You can also mock method calls by passing them in as keys of an associative array:

<?php
use \UA1Labs\Fire\Test\TestCase;

class MyTestCase extends TestCase 
{
    testMyFirstTest()
    {
        $mock = $this->getMockObject(MyClass::class, [
            'myPublicMethod' => 'My Return Value'
        ]);
    }
} 

Checkout the updated FireTest API Documentation!

Leave a comment

Leave a Reply