PHP unit testing framework with built in mocks and stubs. Runs in the browser, or via the command line.

Related tags

Testing Enhance-PHP
Overview

Enhance PHP Build Status

A unit testing framework with mocks and stubs. Built for PHP, in PHP!

Quick Start: Just add EnhanceTestFramework.php and you are ready to go.

Check out the documentation for more:

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

https://github.com/Enhance-PHP/Enhance-PHP

Note - this project is still active. I know you check the revision dates, but we have kept Enhance lightweight and stable, which means we don't need to keep updating it all the time :)

Comments
  • Mock/Stub with multiple calls

    Mock/Stub with multiple calls

    Hi, I try to create a stub with multiple calls, but I don't know to make it...

    With PHPUnit

    $service->expects($this->any()) ->method('readTemp') ->will($this->onConsecutiveCalls(10,12,14));

    With Mockery

    $service->shouldReceive('readTemp')->times(3)->andReturn(10, 12, 14);

    With Phake

    \Phake::when($service)->readTemp()->thenReturn(10) ->thenReturn(12) ->thenReturn(14);

    It's possible to do, thanks.

    opened by isidromerayo 7
  • Change of exception API

    Change of exception API

    I've added Exception handling abilities to the Scenarios class, I'll be comitting it after I've made/altered the unit tests for it. But doing this I've realised that EnhancePHP's support for exceptions isn't great. It doesn't let you specify the exact exception expected, and it also has a strange API for it. Currently, you have to call throws with the classname and method you wish to throw the exception. I understand why this is needed, since you can't catch an exception if the method is called in the actual test. But I've been having a think, and maybe it would be better to utilise PHP's support for anonymous functions. So instead of:

    \Enhance\Assert::throws($someClass, 'MethodName', array(2, 'Arg2', 5));

    You'd call: \Enhance\Assert::throws('ExpectedException', function(){ $someClass->MethodName(2, 'Arg2', 5); });

    This way it follows a more consistent API with the expectations class, they can still specify a non-anonymous callback (e.g. array($someClass, 'MethodName')), and they can specify what callback to expect.

    I'm happy to code this up if anyone likes the idea, but it would cause a change in the API - is this ok with everyone?

    P.S. I couldn't find a good place to discuss this so I made it as an issue, I'm still fairly new to GitHub!

    opened by LewisW 7
  • Romanian language added to the framework

    Romanian language added to the framework

    Hello,

    I really like Enhance PHP Framework because is so easy to use, and because my native language is Romanian I thought that will be a good idea to help the project with a romanian translation.

    Anyway, i want to congratulate you all for the greate work done.

    Best Regard, Tofan Andrei, PHP Developer

    opened by ghost 4
  • Ignore abstract test classes

    Ignore abstract test classes

    TestFixture is an empty class by default used only for discovery, but PHP makes it a pain to redeclare classes, so I usually implement an abstract class that has some shared setUp and tearDown instructions that inherits from TestFixture, and all my concrete test classes inherit from that abstract class.

    The problem is that runTests will break trying to instantiate the abstract class, since it does not check for that. The following is the code I use to patch EnhancePHP on my systems:

    <?php
    private function AddClassIfTest($className)
    {
        $class = new ReflectionClass($className);
        if ($class->isAbstract()) {
            return;
        }
        ...
    ?>
    
    opened by lkraider 2
  • Fix documentation code formatting

    Fix documentation code formatting

    Description: All code in the documentation is being displayed in a single wrapped line of text.

    Expected: Correctly format in multiple lines and syntax-highlight the code.

    Environment: Firefox 12 and Chrome 19 on OS X 10.7

    opened by lkraider 2
  • Mock->verifyExpectations() Throws an uncaught Exception

    Mock->verifyExpectations() Throws an uncaught Exception

    When trying to verify a mock has been correctly accessed using Mock->verifyExpectations() the code throws an Exception (EnhanceTestFramework.php on line 819) this is never caught.

    Looks to me like it should through a TestException as this is handled correctly by Test->run() on line 743

    I've made the change on my local copy and it seems to work well.

    Many thanks for this super lightweight framework

    Cheers

    Tosh

    opened by Toshbrown 1
  • discoverTests should ignore hidden files by default

    discoverTests should ignore hidden files by default

    This is an issue specially on Mac which has .DS_Store files all over the place, and the discoverTests include causes binary data to be output on the test results.

    diff --git a/external/EnhanceTestFramework.php b/external/EnhanceTestFramework.php
    index 2ebcbb4..45486a5 100755
    --- a/external/EnhanceTestFramework.php
    +++ b/external/EnhanceTestFramework.php
    @@ -393,7 +393,7 @@ class EnhanceFileSystem
             $files = array();
             if ($handle = opendir($directory)) {
                 while (false !== ($file = readdir($handle))) {
    -                if ($file != '.' && $file != '..') {
    +                if ($file != '.' && $file != '..' && strpos($file, '.') != 0) {
                         if ($this->isFolderExcluded($file, $excludeRules)){
                             continue;
                         }
    
    opened by lkraider 1
  • Added ability for show the tests that executed a statement in the html report.

    Added ability for show the tests that executed a statement in the html report.

    Now Codespy shows which of your testes executed a certain statement. To do this I have to add one line to Enhance-php's code, in the run function. Basically it is to just assign the function name which is going to be executed to a codespy variable.

    In the html report, when you hover over an executed statement, the browser popup will show you the tests that executed that statement. here is a screen shot. http://i39.tinypic.com/t0m437.jpg

    opened by sandeepcr529 0
  • Updated codespy to latest version.

    Updated codespy to latest version.

    Hi,

    I have updated Codespy to the latest version. The things I have added are.

    • Statement coverage. Approximately calculates the number of executable statements that are inside functions/methods in a file and calculates the number of statements executed among them. This basically counts the number of executable statements (approximated by counting the semicolons) that are inside functions/methods and use it to calculate the coverage.
    • An index.html page that contains the summary of the coverage reports listing file names with line coverage and statement coverage percentages and a link to the code coverage view of the corresponding file.
    • There is a partial implementation of path coverage analysis, but it is not really helpful at this point.

    I have put back the output path to the same directory set by you. So you just have to download and run the index.php in Codespy directory to see its working.

    opened by sandeepcr529 0
  • Various updates

    Various updates

    • Changed CodeCoverageWrapper's constructor to also log the initial call to the __construct method on the proxied class.
    • Added filename and line number info to failed test output.
    • Added checks for all standard PHP types. Note: These need unit tests, which I am working on.
    • Fixed getDescription to work with boolean values.
    opened by LewisW 0
  • Getting Started Code

    Getting Started Code

    I run the Getting Started Code:

    <?php
    
    include_once('EnhanceTestFramework.php');
    // Include your classes and test fixtures - they can be in separate files, just use include() statements for them!
    
    class ExampleClass
    {
        public function addTwoNumbers($a, $b)
        {
            return $a + $b;
        }
    }
    // Naming: By using "extends \Enhance\TestFixture" you signal that the public methods in // your class are tests.
    
    class ExampleClassTests extends \Enhance\TestFixture
    {
        private $target;
    
        public function setUp()
        {
            $this->target = \Enhance\Core::getCodeCoverageWrapper('ExampleClass');
        }
        public function addTwoNumbersWith3and2Expect5()
        {
            $result = $this->target->addTwoNumbers(3, 2);
            \Enhance\Assert::areIdentical(5, $result);
        }
    }
    
    Enhance\Core::runTests();
    
    ```
    
    and get:
    
    `Fatal error: Uncaught TypeError: get_parent_class(): Argument #1 ($object_or_class) must be an object or a valid class name, bool given in /Users/thome/php/public/EnhanceTestFramework.php on line 603`
    
    Can you help to put me on the track?
    codespy 
    opened by tik9 7
  • Composer compatibility

    Composer compatibility

    Hey all.

    I was wondering if Composer compatibility is on the road-map?

    If not, would you accept a PR that created it? I love the test framework, but I'd love to be able to take advantage of Composer's excellent dependency management and Packagist's lovely deployment.

    Cheers

    opened by girvo 7
SimpleTest is a framework for unit testing, web site testing and mock objects for PHP

SimpleTest SimpleTest is a framework for unit testing, web site testing and mock objects for PHP. Installation Downloads All downloads are stored on G

SimpleTest 147 Jun 20, 2022
vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with any unit test framework, like PHPUnit or SimpleTest.

vfsStream vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with

null 1.4k Dec 23, 2022
The modern, simple and intuitive PHP unit testing framework.

atoum PHP version atoum version 5.3 -> 5.6 1.x -> 3.x 7.2 -> 8.x 4.x (current) A simple, modern and intuitive unit testing framework for PHP! Just lik

atoum 1.4k Nov 29, 2022
The PHP Unit Testing framework.

PHPUnit PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. Installat

Sebastian Bergmann 18.8k Jan 4, 2023
Unit testing tips by examples in PHP

Unit testing tips by examples in PHP Introduction In these times, the benefits of writing unit tests are huge. I think that most of the recently start

Kamil RuczyƄski 894 Jan 4, 2023
Real-world Project to learning about Unit Testing/TDD with Laravel for everybody

KivaNote - a Laravel TDD Sample Project Let me introduce you to KivaNote, a simple real-world application using Laravel to show you how the TDD & Unit

(Seth) Phat Tran 10 Dec 31, 2022
Package for unit testing Laravel form request classes

Package for unit testing Laravel form request classes. Why Colin DeCarlo gave a talk on Laracon online 21 about unit testing Laravel form requests cla

null 18 Dec 11, 2022
Learn unit testing with PHPUnit.

PHPUnit Exercise Running PHPUnit ./vendor/bin/phpunit # with filter which tests to run ./vendor/bin/phpunit --filter <pattern> Running Pint ./vendor/

Nopal 2 Aug 23, 2022
Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slowness of constantly restarting the testing environment.

Magic Test for Laravel Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slownes

null 400 Jan 5, 2023
Very simple mock HTTP Server for testing Restful API, running via Docker.

httpdock Very simple mock HTTP Server for testing Restful API, running via Docker. Start Server Starting this server via command: docker run -ti -d -p

Vo Duy Tuan 4 Dec 24, 2021
Mock HTTP requests on the server side in your PHP unit tests

HTTP Mock for PHP Mock HTTP requests on the server side in your PHP unit tests. HTTP Mock for PHP mocks the server side of an HTTP request to allow in

InterNations GmbH 386 Dec 27, 2022
PHP Test Generator - A CLI tool which generates unit tests

This project make usages of PHPStan and PHPParser to generate test cases for a given PHP File.

Alexander Schranz 7 Dec 3, 2022
To run time/IO related unit tests (e.g., sleep function calls, database queries, API calls, etc) faster using Swoole.

To run time/IO related unit tests (e.g., sleep function calls, database queries, API calls, etc) faster using Swoole.

Demin Yin 11 Sep 9, 2022
Full-stack testing PHP framework

Codeception Modern PHP Testing for everyone Codeception is a modern full-stack testing framework for PHP. Inspired by BDD, it provides an absolutely n

Codeception Testing Framework 4.6k Jan 7, 2023
AST based PHP Mutation Testing Framework

Infection - Mutation Testing framework Please read documentation here: infection.github.io Twitter: @infection_php Discord: https://discord.gg/ZUmyHTJ

Infection - Mutation Testing Framework for PHP 1.8k Jan 2, 2023
Pest is an elegant PHP Testing Framework with a focus on simplicity

Pest is an elegant PHP Testing Framework with a focus on simplicity. It was carefully crafted to bring the joy of testing to PHP. Explore the docs: pe

PEST 5.9k Dec 27, 2022
Humbug - a Mutation Testing framework for PHP

Humbug is a Mutation Testing framework for PHP to measure the real effectiveness of your test suites and assist in their improvement. It eats Code Coverage for breakfast.

Humbug 1.1k Dec 28, 2022
A drop in fake logger for testing with the Laravel framework.

Log fake for Laravel A bunch of Laravel facades / services are able to be faked, such as the Dispatcher with Bus::fake(), to help with testing and ass

Tim MacDonald 363 Dec 19, 2022