Giter Site home page Giter Site logo

zend-validator-phpunit-exercises-clean's Introduction

WARNING

This version is meant as a base for PHPUnit exercises. It has most of the unit test stripped and it shouldn't be used in any projects.

After cloning repository perform (inside of project directory):

composer install

Then on Linux:

vendor/bin/phpunit --bootstrap vendor/autoload.php 

On Windows:

vendor\bin\phpunit.bat --bootstrap <full_path_to_project>\vendor\autoload.php

You should see an output like this:

PHPUnit 4.8.35 by Sebastian Bergmann and contributors.

...

Time: 65 ms, Memory: 4.00MB

OK (3 tests, 0 assertions)

You may then configure your IDE of choice as needed. I don't mind.

Excercises

Simple assertion

For method isValid in IsInstanceOf validator, create a test that assures that true is returned when you pass an instance of specified class.

Simple assertion for exception

For method isValid in Db\NoRecordExists validator, create a test that assures that exception is thrown if no adapter was passed.

Hint: you still need to pass 'table' and 'field' option. You can do this either in setup or in the test itself.

Simple mock

Create a mock with no methods or expectations specified (null object) for class IsInstanceOf. Pass it as an argument to isValid of IsInstanceOf validator, which has className set to either \PHPUnit_Framework_MockObject_MockObject::class or IsInstanceOf:class. Create appropriate assertion.

Mock with expects

In Barcode validator - create a mock for class AbstractAdapter with getLength method specified. Make sure that, whatever happens, getLength is always called. Create an assertion for the return value.

Mock with with and will

In Barcode validator - create a mock for class AbstractAdapter with hasValidLength method specified. Make sure that this method will receive the value passed to isValid, will return false and return value will be false.

zend-validator

Build Status Coverage Status

The Zend\Validator component provides a set of commonly needed validators. It also provides a simple validator chaining mechanism by which multiple validators may be applied to a single datum in a user-defined order.

zend-validator-phpunit-exercises-clean's People

Contributors

pmichk avatar

Watchers

James Cloos avatar Dawid Mazur avatar

Forkers

flexicon pbpp

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.