Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpunit 3.7: what happened to the @assert annotation?

Tags:

php

phpunit

I have phpunit 3.7

  • In the documentation of 3.6, Appendix B, there is a @assert annotation, whereas
  • In the documentation of 3.7, Appendix B, there is no @assert annotation

The official announcement mentions some new annotations (and the re-introduction of an old one previously deprecated), but it does not mention the removal of @assert. In the changelog for 3.7., @assert is not to be found on the page

When I run my code on a class using the code snippet

<?php
class MyMathClass
{
   /**
    * Add two given values together and return sum
    * @assert (1,2) == 3
    */
   public function addValues($a,$b)
   {
       return $a+$b;
   }
}

the output is

PHPUnit 3.7.1 by Sebastian Bergmann.



Time: 1 second, Memory: 4.25Mb

No tests executed!

with php 3.6.2

 phpunit MyMathClass.php
PHPUnit 3.6.12 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 2.75Mb

OK (1 test, 1 assertion)
like image 345
knb Avatar asked Sep 27 '12 09:09

knb


People also ask

Where are assertions implemented in PHPUnit?

Assertions — PHPUnit 9.5 Manual 1. Assertions ¶ This appendix lists the various assertion methods that are available. PHPUnit’s assertions are implemented in PHPUnit\Framework\Assert . PHPUnit\Framework\TestCase inherits from PHPUnit\Framework\Assert.

What is the inverse of assertnotcontains in PHP?

assertNotContains () is the inverse of this assertion and takes the same arguments. $ phpunit ContainsTest PHPUnit 9.5.0 by Sebastian Bergmann and contributors.

What is @annotation in PHP?

An annotation is a special form of syntactic metadata that can be added to the source code of some programming languages. While PHP has no dedicated language feature for annotating source code, the usage of tags such as @annotation arguments in a documentation block has been established in the PHP community to annotate source code.

What does assertnotequals () do in PHP?

Reports an error identified by $message if the two variables $expected and $actual are not equal. assertNotEquals () is the inverse of this assertion and takes the same arguments. $ phpunit EqualsTest PHPUnit 9.5.0 by Sebastian Bergmann and contributors.


1 Answers

Answering my own question after doing some research. And thanks to the commenters for putting me on track.

The annotation is gone because it has been moved to the optional PHPUnit_SkeletonGenerator package.

At this time, there are two confusing issues with this:

  1. the removal of the @assert annotation from the phpunit "core"
  2. the documentation being not updated properly

The changelog is imprecise. It says (wrongly):

Removed deprecated --skeleton-class and --skeleton-test switches. The functionality is now provided by the phpunit-skel command of the PHPUnit_SkeletonGenerator package.

A better way of saying this would sound more like this:

Removed deprecated --skeleton-class and --skeleton-test switches. The functionality is now provided by the optional phpunit-skelgen command of the PHPUnit_SkeletonGenerator package. Therefore, the @assert annotation has been removed from the phpunit core. It becomes available after installing PHPUnit_SkeletonGenerator via PEAR.

Maybe I'll change this myself via github and notify the maintainers.

like image 58
knb Avatar answered Nov 15 '22 00:11

knb