Giter Site home page Giter Site logo

webdev-unit-test-example's Introduction

Webdev Unit Test Example

A simple password validator with unit tests, meant to be used as an example.

Requirements

  • PHP 8+
  • Composer

How to run

  1. Install the project dependencies using composer:

    $ composer install
    
  2. Run tests

    $ composer run test
    

Expected output:

PHPUnit 9.5.25

Password Validator
 ✔ It passes a good password
 ✔ It requires at least twelve characters
 ✔ It requires uppercase letters
 ✔ It requires lowercase letters
 ✔ It requires numbers
 ✔ It requires special characters

Time: 00:00.005, Memory: 4.00 MB

OK (6 tests, 6 assertions)

Bonus

There is a commented out test that exposes a bug in our validator. After uncommenting it, you should get the following output:

PHPUnit 9.5.25 #StandWithUkraine

Password Validator
 ✔ It passes a good password
 ✔ It requires at least twelve characters
 ✔ It requires uppercase letters
 ✔ It requires lowercase letters
 ✔ It requires numbers
 ✔ It requires special characters
 ✘ It handles multibyte characters
   ┐
   ├ Failed asserting that true is false.
   │
   ╵ /app/PasswordValidatorTest.php:34

(...)

FAILURES!
Tests: 7, Assertions: 7, Failures: 1.

Can you fix this bug?

webdev-unit-test-example's People

Contributors

lhsazevedo avatar

Watchers

James Cloos avatar  avatar  avatar

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.