Giter VIP home page Giter VIP logo

php_koans's Introduction

PHP Koans

PHP Koans is heavily based on Greg Malcolm's Python Koans, which is based on Edgecase's Ruby Koans. Much credit to both projects. Thank you!

PHP Koans Screenshot

PHP Koans is an interactive tutorial for learning the PHP programming language by making tests pass.

Most tests are fixed by filling the missing parts of assert functions. Eg:

$this->assertEquals(__, 1+2);

which can be fixed by replacing the __ part with the appropriate code:

$this->assertEquals(3, 1+2);

Occasionally you will encounter some failing tests that are already filled out. In these cases, you will need to finish implementing some code to progress. For example, there is an exercise for writing some code that will tell you if a triangle is equilateral, isosceles or scalene.

As well as being a great way to learn some PHP, it is also a good way to get a taste of Test Driven Development (TDD).

Downloading PHP Koans

PHP Koans is available through git on Github:

https://github.com/akoebbe/php_koans

or

Download a zipped copy

Installing PHP Koans

Aside from downloading or checking out the latest version of PHP Koans, you need to install the PHP interpreter.

PHP Koans was written using PHP 8.1. It is recommended that you use PHP 8.1+, though it may work in earlier versions, don't hold your breath.

Only the command line interface (CLI) for PHP is needed as we will not be testing web development.

Windows

  1. Download the zipped binaries from https://windows.php.net/download/ (non-thread safe version is fine)

macOS

macOS bundles PHP, so you may not need to do anything depending on the version installed. To check which version you have open the Terminal app and type

php --version

If you see version 8.1 or higher, you're good to go! If not, then you will want to install a newer version with Homebrew.

Homebrew

  1. Go to https://brew.sh/
  2. Copy the command listed in the Install section and paste it into the Terminal app
  3. Follow the install instructions
  4. Run brew install php to install the latest version
  5. Open a new terminal window or run source ~/.bash_profile
  6. Run php --version, you should now see the latest version of PHP reported

Linux

If you are running Linux, you will use your distributions package manager to install PHP. A few common distribution methods:

Debian/Ubuntu (and variants)

apt-get install php-cli

Fedora

yum install php

If that version is outdated, you can use Remi's Repository to install a newer version. See section 2.1 on Remi's site

Arch

sudo pacman -S php

Dockerization

If you prefer not to install php in your system, you can use a docker container.

To build the image run a terminal, go to the php_koans folder and run:

docker build . -t 'php-koans'

Every time you want to execute the suite run:

docker run -ti php-koans

Getting Started

From a *nix terminal or windows command prompt go to the php_koans folder and run:

php contempate_koans

In my I fire up my Terminal app and run this:

PHP Koans Screenshot

Apparently, a test failed:

Failed asserting that false is true.

It also tells me exactly where the problem is, it's an assert on line 15 of .\koans\AssertKoans.php. This one is easy, just change FALSE to TRUE to make the test pass.

PHPUnit

This koans project uses Sebastian Bergmann's wonderful PHPUnit command (source code). The PHAR binary is included in this project for convenience and to lower the setup curve. It has been renamed from phpunit to contemplate_koans to fit with the theme of this project. See LICENSE_PHPUnit for the relevant license information.

Work in Progress

This project and document are a work in progress. There is still much to do and many people to thank. Please bear with me (and contribute!) as the project progresses.

These are the list of koans from Python Koans to be ported over to PHP Koans.

php_koans's People

Contributors

akoebbe avatar asieralba10 avatar demipel8 avatar ericjgruber avatar ericpoe avatar johnkary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

php_koans's Issues

Migrate the PHPUnit custom printers to the event system

Because PHPUnit 10 did away with the printerClass config setting, the band-new-developer friendly output no longer works. There is a new event base architecture that needs to be used, either directly or some existing adapter plugin. I would rather not use plugin/library for several reasons, the primary being I don't want to add to the installation process for new users.

There are a few projects that have accomplished migrating to the event system and it's worth looking at how they did it and follow their pattern. Examples are czim/phpunit-printer and paratest. The latter looks more straight forward, but there might something I'm missing.

So we need to migrate https://github.com/akoebbe/php_koans/blob/master/KoansLib/KoanPrinter.php to work with phpunit 10+

Automagically include the latest version of phpunit.phar in the repo

Rather than manually checking in the latest phpunit.phar file and rename it to contemplate_koans, we should make it an automatic download/checksum/chmod/rename via CI (github actions) whenever new code is pushed in to php_koans. This will also protect against a malicious version of phpunit sneaking via a contributor. I haven't messed with Github actions to know if this is possible or straightforward.

Unable to run koan using contemplate koans after update to PHP8.1

Due to the latest updates to PHP 8.1, running the koan using php contemplate_koans is not working anymore, see picture below:
Screenshot 2022-11-30 at 17 47 20

We can improve the way koans are executed and we can simplify the project by avoiding running the koans using contemplate and run them using phpunit.

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.