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 addrequire '_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 byrequire
): for example if the Solution contains the lineecho "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 therequire
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
-
- The preloaded section, the solution and the tests are split in 3 files, respectively:
-
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
- Runner prepends this if
-
⚠️ 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 mereE_NOTICE
. The runner treatsE_WARNING
S 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
- 'Magic' recursion call depth number
- Burrows-Wheeler-Transformation
- Check and Mate?
- Creating a custom PHP stream wrapper
- Divide numbers as strings
- Domain name validator
- 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 - Evaluate mathematical expression
- Fibo akin
- Financing Plan on Planet XY140Z-n
- Fluent Calculator
- How many dots are covered
- Implement the (Unnormalized) Cardinal Sine
- Largest Palindromic Product
- List of all Rationals
- Mirrored Exponential Chunks
- Mystery Class
- 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
- PHP in Action #5 - PHPMailer Intro
- Reflection in PHP #3 - Using Reflection on Classes
- Reflection in PHP #4 - Puzzle Challenge [Assessment]
- RoboScript #4 - RS3 Patterns to the Rescue
- Text align justify
- The Walker
- We are Family
After changing assertEquals with assertSame to avoid this problem some katas failed the automatic change and require manual editing:
- Binary Genetic Algorithms
- Calculate mean and concatenate string
- Creating a custom PHP stream wrapper
- Disease Spread
- Easy Cyclist's Training
- Euclidean distance in n dimensions
- Fibonacci, Tribonacci and friends
- Financing Plan on Planet XY140Z-n
- Find the Middle of the Product
- Find the area of the rectangle!
- FizzBuzz++
- Fun with lists: filter
- Fun with lists: map
- How good are you really?
- How many dots are covered
- Molecule to atoms
- Ordered Count of Characters
- Parse a linked list from a string
- Pascal's Triangle
- Program a Calculator #2 - 3D Vectors
- Return the first M multiples of N
- Simple Fun #181: Rounding
- Simple Fun #74: Growing Plant
- Simple Fun #87: Shuffled Array
- Sum and Length
- Sum of Array Averages
- Sum of Intervals
- The Walker
- Tiny Three-Pass Compiler
- Tortoise racing
- We are Family