List of PHP Kata to Update - codewars/content-issues GitHub Wiki

PHP 8.0 with PHPUnit 9.5.2 was added. The kata on this page needs to be updated manually. Any help is appreciated!

Summary of Changes

  • Files are no longer concatenated, but it should work very similarly as before because solution and preloaded files are autoloaded.

    • The preloaded section, the solution and the tests are split in 3 files, respectively: /workspace/default/_preloaded.php, /workspace/default/_solution.php and /workspace/default/tests/{PHPUnit Test Class Name}.php.
    • ⚠️ Breaking change: Global variables from the Solution are no longer accessible out of the box. This has several consequences:
      • Solutions that use global variables no longer work (the global variables will be evaluated to null).

      • While most kata ask the user to write a function or a class, some ask the user to define a global variable (for example Binary Multiple of 3 which asks for a regexp). A global declaration is no longer sufficient to pull the Solution file's global variables into the Test file's scope. A possible fix is to add require '_solution.php'; at the top level of the test suite as well (require_once will not work). However, this will cause the Solution file to be evaluated twice (once by the auto-loading and once by require): for example if the Solution contains the line echo "foo"; at the top-level, foo will be printed twice to the console. Despite this caveat, require still allows to upgrade those kata that only ask for one or several variables. But this will not work when the kata requires both global variables and functions / classes from the user, as the second evaluation caused by the require statement will trigger a duplicate declaration error, e.g.:

        Fatal error: Cannot redeclare foo() (previously declared in /workspace/default/_solution.php:3) in /workspace/default/_solution.php on line 1
        
      Some kata seem impossible to upgrade due to this new runner behavior, see the list below. If you know a way to solve this problem, please get in touch !
  • The name of the test class is now required to end with Test

    • ⚠️ Breaking change: The test class must always be the first class within the test suite's file. If there are other classes besides the test class (for example a class for the reference solution, or for a random tests generator), they must be defined after the test class.
  • Solution and Preloaded file should have <?php

    • Runner prepends this if missing for backwards compatibility, but any new code should include it
  • Test file should have <?php use PHPUnit\Framework\TestCase;

    • Runner prepends this if <?php is missing for backwards compatibility, but any new code should include it
  • ⚠️ Breaking change: From PHP 8.0 on, attempting to access an array key which has not been defined or an out-of-bounds string index will raise an E_WARNING instead of a mere E_NOTICE. The runner treats E_WARNINGS as errors, and aborts the program when one is emitted. As a consequence many solutions containing such accesses no longer pass the tests.

  • PHPUnit is updated to 9.5.2 so there are some breaking changes

    • Testing for exceptions:

      PHPUnit 6 removed support for testing for exceptions with PHPDoc annotations:

     /**
       * @expectedException InvalidArgumentException
       * @expectedExceptionMessage The argument was invalid!
     */
     public function testForException()
     {
         functionThatShouldThrow();
     }
    

    new code should use expectException():

    public function testForException()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage("The argument was invalid!");
        functionThatShouldThrow();
    }
    

List of Kata

  1. 'Magic' recursion call depth number
  2. Burrows-Wheeler-Transformation
  3. Check and Mate?
  4. Creating a custom PHP stream wrapper
  5. Divide numbers as strings
  6. Domain name validator
  7. Don't rely on luck. - Potentially impossible to upgrade since the solution and tests are no longer concatenated: calling srand() in the solution has no effect on the tests
  8. Evaluate mathematical expression
  9. Fibo akin
  10. Financing Plan on Planet XY140Z-n
  11. Fluent Calculator
  12. How many dots are covered
  13. Implement the (Unnormalized) Cardinal Sine
  14. Largest Palindromic Product
  15. List of all Rationals
  16. Mirrored Exponential Chunks
  17. Mystery Class
  18. Object-Oriented PHP #1 - Classes, Public Properties and Methods - Potentially impossible to upgrade as it requires the user to write both a class and 3 global variables, see above
  19. PHP in Action #5 - PHPMailer Intro
  20. Reflection in PHP #3 - Using Reflection on Classes
  21. Reflection in PHP #4 - Puzzle Challenge [Assessment]
  22. RoboScript #4 - RS3 Patterns to the Rescue
  23. Text align justify
  24. The Walker
  25. We are Family

After changing assertEquals with assertSame to avoid this problem some katas failed the automatic change and require manual editing:

  1. Binary Genetic Algorithms
  2. Calculate mean and concatenate string
  3. Creating a custom PHP stream wrapper
  4. Disease Spread
  5. Easy Cyclist's Training
  6. Euclidean distance in n dimensions
  7. Fibonacci, Tribonacci and friends
  8. Financing Plan on Planet XY140Z-n
  9. Find the Middle of the Product
  10. Find the area of the rectangle!
  11. FizzBuzz++
  12. Fun with lists: filter
  13. Fun with lists: map
  14. How good are you really?
  15. How many dots are covered
  16. Molecule to atoms
  17. Ordered Count of Characters
  18. Parse a linked list from a string
  19. Pascal's Triangle
  20. Program a Calculator #2 - 3D Vectors
  21. Return the first M multiples of N
  22. Simple Fun #181: Rounding
  23. Simple Fun #74: Growing Plant
  24. Simple Fun #87: Shuffled Array
  25. Sum and Length
  26. Sum of Array Averages
  27. Sum of Intervals
  28. The Walker
  29. Tiny Three-Pass Compiler
  30. Tortoise racing
  31. We are Family