diff --git a/LICENSE b/LICENSE index 31309b1..a9e4555 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014-2017 MyBuilder Limited +Copyright (c) 2014-2018 MyBuilder Limited Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 7469efe..b81d454 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,15 @@ [![Build Status](https://secure.travis-ci.org/mybuilder/phpunit-accelerator.svg?branch=master)](http://travis-ci.org/mybuilder/phpunit-accelerator) -Inspired by [Kris Wallsmith faster PHPUnit article](http://kriswallsmith.net/post/18029585104/faster-phpunit), we've created a [PHPUnit](http://phpunit.de) test listener that speeds up PHPUnit tests about 20% by freeing memory. +*Depreciation * +Our latest benchmarking shows that there is now little improvement with PHPUnit Accelerator. +PHPUnit itself has made changes which do a lot of this now. Our plan is not to update this going forward unless we can find other areas we can speed up. ## Installation To install this library, run the command below and you will get the latest version -``` bash +```bash composer require mybuilder/phpunit-accelerator --dev ``` @@ -36,8 +38,8 @@ As an example, if we hypothetically wanted to ignore all tests which include "Le use MyBuilder\PhpunitAccelerator\IgnoreTestPolicy; class IgnoreLegacyTestPolicy implements IgnoreTestPolicy { - public function shouldIgnore(\ReflectionObject $testReflection) { - return strpos($testReflection->getFilename(), 'Legacy') !== false; + public function shouldIgnore(\ReflectionObject $testReflection): bool { + return strpos($testReflection->getFileName(), 'Legacy') !== false; } } ``` @@ -56,6 +58,9 @@ And pass it to the constructor of our test listener in `phpunit.xml` configurati ``` +Inspired by [Kris Wallsmith faster PHPUnit article](http://kriswallsmith.net/post/18029585104/faster-phpunit), we've created a [PHPUnit](http://phpunit.de) test listener that speeds up PHPUnit tests about 20% by freeing memory. + --- -Created by [MyBuilder](http://www.mybuilder.com/) - Check out our [blog](http://tech.mybuilder.com/) for more insight into this and other open-source projects we release. +Created by [MyBuilder](https://www.mybuilder.com/) - Check out our [blog](https://tech.mybuilder.com/) for more insight into this and other open-source projects we release. +We are always looking to hire good people for our London office. diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b5fdd90..736854c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,7 +10,6 @@ convertWarningsToExceptions = "true" processIsolation = "false" stopOnFailure = "true" - syntaxCheck = "false" bootstrap = "./vendor/autoload.php" > diff --git a/src/IgnoreTestPolicy.php b/src/IgnoreTestPolicy.php index fba2a6b..f868111 100644 --- a/src/IgnoreTestPolicy.php +++ b/src/IgnoreTestPolicy.php @@ -4,8 +4,5 @@ interface IgnoreTestPolicy { - /** - * @return boolean - */ - public function shouldIgnore(\ReflectionObject $testReflection); + public function shouldIgnore(\ReflectionObject $testReflection):bool; } diff --git a/src/TestListener.php b/src/TestListener.php index cd42476..3041389 100644 --- a/src/TestListener.php +++ b/src/TestListener.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestListener as BaseTestListener; use PHPUnit\Framework\TestListenerDefaultImplementation; +use PHPUnit\Framework\Test; class TestListener implements BaseTestListener { @@ -11,14 +12,14 @@ class TestListener implements BaseTestListener private $ignorePolicy; - const PHPUNIT_PROPERTY_PREFIX = 'PHPUnit_'; + private const PHPUNIT_PROPERTY_PREFIX = 'PHPUnit_'; public function __construct(IgnoreTestPolicy $ignorePolicy = null) { - $this->ignorePolicy = ($ignorePolicy) ?: new NeverIgnoreTestPolicy(); + $this->ignorePolicy = $ignorePolicy ?: new NeverIgnoreTestPolicy(); } - public function endTest(\PHPUnit\Framework\Test $test, float $time): void + public function endTest(Test $test, float $time): void { $testReflection = new \ReflectionObject($test); @@ -29,7 +30,7 @@ public function endTest(\PHPUnit\Framework\Test $test, float $time): void $this->safelyFreeProperties($test, $testReflection->getProperties()); } - private function safelyFreeProperties(\PHPUnit\Framework\Test $test, array $properties) + private function safelyFreeProperties(Test $test, array $properties) { foreach ($properties as $property) { if ($this->isSafeToFreeProperty($property)) { @@ -48,7 +49,7 @@ private function isNotPhpUnitProperty(\ReflectionProperty $property) return 0 !== strpos($property->getDeclaringClass()->getName(), self::PHPUNIT_PROPERTY_PREFIX); } - private function freeProperty(\PHPUnit\Framework\Test $test, \ReflectionProperty $property) + private function freeProperty(Test $test, \ReflectionProperty $property) { $property->setAccessible(true); $property->setValue($test, null); @@ -57,7 +58,7 @@ private function freeProperty(\PHPUnit\Framework\Test $test, \ReflectionProperty class NeverIgnoreTestPolicy implements IgnoreTestPolicy { - public function shouldIgnore(\ReflectionObject $testReflection) + public function shouldIgnore(\ReflectionObject $testReflection): bool { return false; } diff --git a/tests/TestListenerTest.php b/tests/TestListenerTest.php index 7ebc91a..e0baf99 100644 --- a/tests/TestListenerTest.php +++ b/tests/TestListenerTest.php @@ -5,6 +5,7 @@ class TestListenerTest extends \PHPUnit\Framework\TestCase { + /** @var DummyTest */ private $dummyTest; protected function setUp() @@ -12,52 +13,43 @@ protected function setUp() $this->dummyTest = new DummyTest(); } - /** - * @test - */ - public function shouldFreeTestProperty() + public function testShouldFreeTestProperty():void { $this->endTest(new TestListener()); $this->assertFreesTestProperty(); } - private function endTest(TestListener $listener) + private function endTest(TestListener $listener):void { $listener->endTest($this->dummyTest, 0); } - private function assertFreesTestProperty() + private function assertFreesTestProperty():void { $this->assertNull($this->dummyTest->property); } - /** - * @test - */ - public function shouldNotFreePhpUnitProperty() + public function testShouldNotFreePhpUnitProperty():void { $this->endTest(new TestListener()); $this->assertDoesNotFreePHPUnitProperty(); } - private function assertDoesNotFreePHPUnitProperty() + private function assertDoesNotFreePHPUnitProperty():void { $this->assertNotNull($this->dummyTest->phpUnitProperty); } - /** - * @test - */ - public function shouldNotFreeTestPropertyWithIgnoreAlwaysPolicy() + public function testShouldNotFreeTestPropertyWithIgnoreAlwaysPolicy(): void { $this->endTest(new TestListener(new AlwaysIgnoreTestPolicy())); $this->assertDoesNotFreeTestProperty(); } - private function assertDoesNotFreeTestProperty() + private function assertDoesNotFreeTestProperty():void { $this->assertNotNull($this->dummyTest->property); } @@ -75,7 +67,7 @@ class DummyTest extends \PHPUnit_Fake class AlwaysIgnoreTestPolicy implements IgnoreTestPolicy { - public function shouldIgnore(\ReflectionObject $testReflection) + public function shouldIgnore(\ReflectionObject $testReflection): bool { return true; }