Search

Asserts

Special module for using asserts in your tests.

Actions

assertArrayHasKey

  • param $key
  • param $actual
  • param $description

assertArrayNotHasKey

  • param $key
  • param $actual
  • param $description

assertContains

Checks that haystack contains needle

  • param $needle
  • param $haystack
  • param string $message

assertCount

  • param $expectedCount
  • param $actual
  • param $description

assertEmpty

Checks that variable is empty.

  • param $actual
  • param string $message

assertEquals

Checks that two variables are equal.

  • param $expected
  • param $actual
  • param string $message
  • param float $delta

assertEqualsCanonicalizing

not documented

assertEqualsIgnoringCase

not documented

assertEqualsWithDelta

not documented

assertFalse

Checks that condition is negative.

  • param $condition
  • param string $message

assertFileExists

Checks if file exists

  • param string $filename
  • param string $message

assertFileNotExists

Checks if file doesn’t exist

  • param string $filename
  • param string $message

assertGreaterOrEquals

  • param $expected
  • param $actual
  • param $description

assertGreaterThan

Checks that actual is greater than expected

  • param $expected
  • param $actual
  • param string $message

assertGreaterThanOrEqual

Checks that actual is greater or equal than expected

  • param $expected
  • param $actual
  • param string $message

assertInstanceOf

  • param $class
  • param $actual
  • param $description

assertInternalType

  • param $type
  • param $actual
  • param $description

assertIsArray

not documented

assertIsBool

not documented

assertIsCallable

not documented

assertIsEmpty

  • param $actual
  • param $description

assertIsFloat

not documented

assertIsInt

not documented

assertIsNotArray

not documented

assertIsNotBool

not documented

assertIsNotCallable

not documented

assertIsNotFloat

not documented

assertIsNotInt

not documented

assertIsNotNumeric

not documented

assertIsNotObject

not documented

assertIsNotResource

not documented

assertIsNotScalar

not documented

assertIsNotString

not documented

assertIsNumeric

not documented

assertIsObject

not documented

assertIsResource

not documented

assertIsScalar

not documented

assertIsString

not documented

assertLessOrEquals

  • param $expected
  • param $actual
  • param $description

assertLessThan

Checks that actual is less than expected

  • param $expected
  • param $actual
  • param string $message

assertLessThanOrEqual

Checks that actual is less or equal than expected

  • param $expected
  • param $actual
  • param string $message

assertNotContains

Checks that haystack doesn’t contain needle.

  • param $needle
  • param $haystack
  • param string $message

assertNotEmpty

Checks that variable is not empty.

  • param $actual
  • param string $message

assertNotEquals

Checks that two variables are not equal

  • param $expected
  • param $actual
  • param string $message
  • param float $delta

assertNotEqualsCanonicalizing

not documented

assertNotEqualsIgnoringCase

not documented

assertNotEqualsWithDelta

not documented

assertNotFalse

Checks that the condition is NOT false (everything but false)

  • param $condition
  • param string $message

assertNotInstanceOf

  • param $class
  • param $actual
  • param $description

assertNotNull

Checks that variable is not NULL

  • param $actual
  • param string $message

assertNotRegExp

Checks that string not match with pattern

  • param string $pattern
  • param string $string
  • param string $message

assertNotSame

Checks that two variables are not same

  • param $expected
  • param $actual
  • param string $message

assertNotTrue

Checks that the condition is NOT true (everything but true)

  • param $condition
  • param string $message

assertNull

Checks that variable is NULL

  • param $actual
  • param string $message

assertRegExp

Checks that string match with pattern

  • param string $pattern
  • param string $string
  • param string $message

assertSame

Checks that two variables are same

  • param $expected
  • param $actual
  • param string $message

assertStringContainsString

not documented

assertStringContainsStringIgnoringCase

not documented

assertStringEndsNotWith

  • Available since 1.1.0 of module-asserts

assertStringEndsWith

  • Available since 1.1.0 of module-asserts

assertStringNotContainsString

not documented

assertStringNotContainsStringIgnoringCase

not documented

assertStringStartsNotWith

Checks that a string doesn’t start with the given prefix.

  • param string $prefix
  • param string $string
  • param string $message

assertStringStartsWith

Checks that a string starts with the given prefix.

  • param string $prefix
  • param string $string
  • param string $message

assertTrue

Checks that condition is positive.

  • param $condition
  • param string $message

expectException

Handles and checks exception called inside callback function. Either exception class name or exception instance should be provided.

<?php
$I->expectException(MyException::class, function() {
    $this->doSomethingBad();
});

$I->expectException(new MyException(), function() {
    $this->doSomethingBad();
});

If you want to check message or exception code, you can pass them with exception instance:

<?php
// will check that exception MyException is thrown with "Don't do bad things" message
$I->expectException(new MyException("Don't do bad things"), function() {
    $this->doSomethingBad();
});

@deprecated Use expectThrowable() instead

  • param $exception string or \Exception
  • param $callback

expectThrowable

Handles and checks throwables (Exceptions/Errors) called inside the callback function. Either throwable class name or throwable instance should be provided.

<?php
$I->expectThrowable(MyThrowable::class, function() {
    $this->doSomethingBad();
});

$I->expectThrowable(new MyException(), function() {
    $this->doSomethingBad();
});

If you want to check message or throwable code, you can pass them with throwable instance:

<?php
// will check that throwable MyError is thrown with "Don't do bad things" message
$I->expectThrowable(new MyError("Don't do bad things"), function() {
    $this->doSomethingBad();
});
  • param $throwable string or \Throwable
  • param $callback

fail

Fails the test with message.

  • param $message

 

Module reference is taken from the source code. Help us to improve documentation. Edit module reference
Don't know how to write tests on your own? We will build or improve them for you. Request a quote for official enterprise support or trainings