From 0a3e90116c073cc2ba9477a2cd99077aa4d97395 Mon Sep 17 00:00:00 2001 From: Gavin Love Date: Fri, 8 Jun 2018 13:43:51 +0100 Subject: [PATCH 1/4] Update licence and readme --- LICENSE | 2 +- README.md | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) 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..4724136 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Inspired by [Kris Wallsmith faster PHPUnit article](http://kriswallsmith.net/pos 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 +36,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; } } ``` @@ -58,4 +58,5 @@ And pass it to the constructor of our test listener in `phpunit.xml` configurati --- -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. From 38c5ceaf662d667d3f5a4f1b0e60f089bc4039ae Mon Sep 17 00:00:00 2001 From: Gavin Love Date: Fri, 8 Jun 2018 13:44:09 +0100 Subject: [PATCH 2/4] Remove no longer used option from phpunit.xml --- phpunit.xml.dist | 1 - 1 file changed, 1 deletion(-) 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" > From 191537194c53952f4ae1e8b29c1089c1d0571b38 Mon Sep 17 00:00:00 2001 From: Gavin Love Date: Fri, 8 Jun 2018 13:44:28 +0100 Subject: [PATCH 3/4] General 7.X tidyups --- src/IgnoreTestPolicy.php | 5 +---- src/TestListener.php | 13 +++++++------ tests/TestListenerTest.php | 26 +++++++++----------------- 3 files changed, 17 insertions(+), 27 deletions(-) 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; } From 240b49c3862db15c3b01f5e4a98e3632bbb909e9 Mon Sep 17 00:00:00 2001 From: Gavin Love Date: Fri, 8 Jun 2018 14:33:34 +0100 Subject: [PATCH 4/4] Add deprecation notice --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4724136..b81d454 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ [![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 @@ -56,6 +58,8 @@ 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](https://www.mybuilder.com/) - Check out our [blog](https://tech.mybuilder.com/) for more insight into this and other open-source projects we release.