2017 © Pedro Peláez
 

library phpunit-assert-exception

Assert exception/throwable/error PHPUnit trait.

image

vladahejda/phpunit-assert-exception

Assert exception/throwable/error PHPUnit trait.

  • Friday, March 23, 2018
  • by VladaHejda
  • Repository
  • 2 Watchers
  • 14 Stars
  • 10,728 Installations
  • PHP
  • 14 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 10 Versions
  • 4 % Grown

The README.md

PhpUnitAssertException

AssertException is a trait, so it can be easily used in your test case., (*1)

  • For PHP 7.1 and PHPUnit 6 compatibility require version 1.3.
  • For PHP 7.1 compatibility require version 1.2.
  • For PHP 7 compatibility require version 1.1.
  • For PHP 5 compatibility require version 1.0.

Install

$ composer require vladahejda/phpunit-assert-exception

Usage

<?php

class MyTest extends \PHPUnit\Framework\TestCase
{
    use VladaHejda\AssertException;

    public function testMultipleExceptionsAtOnce()
    {
        $test = function () {
            // here comes some test stuff of your unit (tested class)
            // which you expect that will throw an Exception
            throw new InvalidArgumentException('Some message 12345', 100);
        };

        // just test if function throws an Exception
        $this->assertException($test); // pass

        // test class of an Exception
        $this->assertException($test, InvalidArgumentException::class); // pass

        // test Exception code
        $this->assertException($test, null, 100); // pass

        // test Exception message
        $this->assertException($test, null, null, 'Some message 12345'); // pass
        $this->assertException($test, null, null, 'Some message'); // also pass, because it checks on substring level

        // test all
        $this->assertException($test, InvalidArgumentException::class, 100, 'Some message 12345'); // pass

        // and here some failing tests
        // wrong class
        $this->assertException($test, ErrorException::class); // fail
        // wrong code
        $this->assertException($test, InvalidArgumentException::class, 200); // fail
        // wrong message
        $this->assertException($test, InvalidArgumentException::class, 100, 'Bad message'); // fail
    }
}

Also see an assertError and assertThrowable methods, which tests if PHP internal Error was thrown, or any Throwable respectively., (*2)

The Versions

23/03 2018

dev-master

9999999-dev

Assert exception/throwable/error PHPUnit trait.

  Sources   Download

BSD-3-Clause

The Requires

 

phpunit

23/02 2017

v1.3.0

1.3.0.0

Assert exception/throwable/error PHPUnit trait.

  Sources   Download

BSD-3-Clause

The Requires

 

phpunit

18/01 2017

dev-php5

dev-php5

Assert exception PHP Unit trait.

  Sources   Download

BSD-3-Clause

The Requires

 

phpunit

18/01 2017

v1.0.1

1.0.1.0

Assert exception PHP Unit trait.

  Sources   Download

BSD-3-Clause

The Requires

 

phpunit

18/01 2017

v1.2.1

1.2.1.0

Assert exception/throwable/error PHP Unit trait.

  Sources   Download

BSD-3-Clause

The Requires

 

phpunit

18/01 2017

dev-php7

dev-php7

Assert exception/throwable/error PHP Unit trait.

  Sources   Download

BSD-3-Clause

The Requires

 

phpunit

18/01 2017

v1.1.1

1.1.1.0

Assert exception/throwable/error PHP Unit trait.

  Sources   Download

BSD-3-Clause

The Requires

 

phpunit

17/01 2017

v1.2.0

1.2.0.0

Assert exception/throwable/error PHP Unit trait.

  Sources   Download

BSD-3-Clause

The Requires

 

phpunit

17/01 2017

v1.1.0

1.1.0.0

Assert exception/throwable/error PHP Unit trait.

  Sources   Download

BSD-3-Clause

The Requires

 

phpunit

23/10 2015

v1.0.0

1.0.0.0

Assert exception PHP Unit trait.

  Sources   Download

BSD-3-Clause

The Requires

 

phpunit