Coder Social home page Coder Social logo

assert's Introduction

Build Status Coverage Status

Assert

This is a simple library that contains a function to asset conditions.

Installation

composer require tebru/assert:~0.2

Usage

Using the generic assert functions, you must pass a condition as the first argument.

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.

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.

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:

  • 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

<?php

namespace Foo;

use function Tebru\assert;

assert(false);

assert's People

Contributors

natebrunette avatar

Stargazers

Brian Litzinger avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

mh-ing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.