Dummy - they just do nothing
Stub - care with specific arguments only
Spy - care that method is called
Mock - delayed version of Spy
Fake - fake saving into databse etc.
<?php
class MyTest extends PHPUnit_Framework_TestCase
{
public function testSomething()
{
$class = new Vendor\Library\Class();
$this->assertEquals('something', $class->getSomething());
}
}
<?php
class MyTest extends PHPUnit_Framework_TestCase
{
public function testSomething()
{
$prophet = new Prophecy\Prophet;
$mock = $prophet->prophesize('App\Entity\User');
$class = new Vendor\Library\Class($mock->reveal());
$mock->someMethod()->shouldBeCalled();
$this->assertEquals('something', $class->getSomething());
$prophet->checkPredictions();
}
}
<?php
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class TestController extends Controller
{
public function indexAction()
{
$products = $this
->getDoctrine()
->getRepository('AppBundle:Product')
->findAll()
;
return $this->render('hello/index.html.twig', array('products' => $products));
}
}
<?php
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class TestController extends Controller
{
public function indexAction($repository)
{
$products = $repository->getAllProducts();
return $this->render('hello/index.html.twig', array('products' => $products));
}
}
git pull && composer update
As a result of an engine rewrite with focus on more efficient data structures, PHP 7 offers much improved performance and memory usage
<?php
declare(strict_types = 1);
class Foo
{
function increment(int $a): int
{
return $a + 1.0; // strictly type checked return
}
}