Skip to content

Instantly share code, notes, and snippets.

@vikbert
Last active July 24, 2018 20:38
Show Gist options
  • Select an option

  • Save vikbert/afc31ab651f13edc72b6a36f7bdcf3b6 to your computer and use it in GitHub Desktop.

Select an option

Save vikbert/afc31ab651f13edc72b6a36f7bdcf3b6 to your computer and use it in GitHub Desktop.
[coding_dojo] #dojo, #coding,

composer project with autoloader

  1. prepare the project files structure
mkdir coding_test
cd coding_test
mkdir src tests
touch composer.json
  1. update the composer.json with the following content:
{
    "autoload": {
        "psr-4": {
            "CodingTest\\": "src"
        },
        "classmap": [
            "src"
        ]
    },
    "require": {
    }
}

  1. then install dependencies
composer require phpunit/phpunit
  1. create Calculator.php in src with the following content:
<?php

namespace CodingTest;

class Calculator
{
    public function __construct()
    {
    }
}
  1. create CalculatorTest.php in tests with following content:
<?php

use PHPUnit\Framework\TestCase;
use CodingTest\Calculator;

class CalculatorTest extends TestCase
{
    public function testFoo()
    {
        $cal = new Calculator();
        $this->assertTrue(true);
    }
}

  1. execute the test vendor/bin/phpunit --colors tests/CalculatorTest.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment