2017 © Pedro Peláez
 

library assert

Simple function to assert conditions

image

tebru/assert

Simple function to assert conditions

  • Sunday, August 16, 2015
  • by natebrunette
  • Repository
  • 2 Watchers
  • 2 Stars
  • 28,282 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

Build Status Coverage Status, (*1)

Assert

This is a simple library that contains a function to asset conditions., (*2)

Installation

composer require tebru/assert:~0.2

Usage

Using the generic assert functions, you must pass a condition as the first argument., (*3)

Simple

The easiest and most generic way to use this library is through assertThat(). This will throw a LogicException with a default message that is easily customized., (*4)

Tebru\assertThat(false);
Tebru\assertThat(1 === 2);
Tebru\assertThat(false, 'My %s %s', 'test', 'message');

Changing exceptions

If you need to throw specific exceptions, that can be done through assert(). The method defaults to throwing a LogicException., (*5)

Tebru\assert(false);
Tebru\assert(1 === 2);
Tebru\assert(false, new \InvalidArgumentException('My custom error message'));

Additional Functions

There are a number of additional functions that assert specific conditions. Each one accepts a message and a variable number of arguments to be used with an sprintf function as the final arguments. A list is provided below with the method definition:, (*6)

  • assertEqual($expected, $actual, $message = null, $_ = null)
  • assertNotEqual($expected, $actual, $message = null, $_ = null)
  • assertSame($expected, $actual, $message = null, $_ = null)
  • assertNotSame($expected, $actual, $message = null, $_ = null)
  • assertTrue($value, $message = null, $_ = null)
  • assertFalse($value, $message = null, $_ = null)
  • assertNull($value, $message = null, $_ = null)
  • assertNotNull($value, $message = null, $_ = null)
  • assertArrayKeyExists($key, array $search, $message = null, $_ = null)
  • assertArrayKeyNotExists($key, array $search, $message = null, $_ = null)
  • assertCount($expected, $countable, $message = null, $_ = null)

Advanced Usage

Starting with php 5.6, you can import functions, (*7)

<?php

namespace Foo;

use function Tebru\assert;

assert(false);

The Versions

16/08 2015

dev-master

9999999-dev

Simple function to assert conditions

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires

by Nate Brunette

16/08 2015

v0.2.0

0.2.0.0

Simple function to assert conditions

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires

by Nate Brunette

01/02 2015

v0.1.0

0.1.0.0

Simple function to assert conditions

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires

by Nate Brunette