Interested in a question, I am reading now about unit testing, including about
PHPUNIT Framework

In the examples and in the Habré, only ООП Code testing is shown.
PHPUNIT if you can test the процедурный код through PHPUNIT
Or is there a similar Frameworks for a процедурного approach?
Bylby is grateful for the link to the article.

  • one
    And what exactly is stopping you from testing the procedural code through PHPUnit? - E_p

1 answer 1

some.php

 <?php function add($a, $b) { // Validation here. return $a + b; } 

test / some.php

 <?php use PHPUnit\Framework\TestCase; require('some.php'); // or use autoload. class SomeTest extends TestCase { public function testAdd() { // Assert $this->assertEquals(3, add(1, 2)); //... } } 

http://respect.imtqy.com/Validation/

Respect \ Validation

 <?php use Respect\Validation\Validator as v; require('some.php'); if (!v::equals(3)->validate(add(1, 2))) { "Error"; } 

Or even better what libraries:

 <?php require('some.php'); if (3 !== add(1, 2)) { "Error"; } 
  • would be cool to add minimal comments - etki
  • @Etki Not really sure. Comments to the code or just a description? - E_p
  • Yes, I saw this code from the habrahabr article, but it is in OOP style, and I need an example on procedural) Although I already found a codeception, it is more understandable, although phpunit is already getting to the head slowly - hovdev
  • @ S1lllver Then your question is not correct. ;) - E_p
  • @ S1lllver you will actually find any validator library for example respect.imtqy.com/Validation . Write as you want and then run the test via php test.php - E_p