-
Notifications
You must be signed in to change notification settings - Fork 1
List of PHP Kata to Update
PHP 8.0 with PHPUnit 9.5.2 was added. The kata on this page needs to be updated manually. Any help is appreciated!
-
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.phpand/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
globaldeclaration 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_oncewill 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,foowill be printed twice to the console. Despite this caveat,requirestill 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 therequirestatement 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
<?phpis 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 anE_WARNINGinstead of a mereE_NOTICE. The runner treatsE_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(); }
-
- 'Magic' recursion call depth number
- Burrows-Wheeler-Transformation
- Check and Mate?
- Creating a custom PHP stream wrapper
- Divide numbers as strings
-
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
- Fluent Calculator
- How many dots are covered
- Implement the (Unnormalized) Cardinal Sine
- Largest Palindromic Product
- 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
- 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 #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
- Agda Kata that require rank adjustment
- List of Possible Duplicate Kata
- List of kata that are candidates to retirement
- List of Kata with font Tag in Description (possibly broken)
- Potentially Plagiarized Kata
- Tags and topics to assign to kata
- List of Agda Kata to Update
- List of C Kata to Update
- List of C++ Kata to Update
- List of COBOL Kata to Update
- List of Coq Kata to Update
- List of Crystal Kata to Update
- List of C# Kata to Update
- List of Dart Kata to Update
- List of Elixir Kata to Update
- List of Go Kata to Update
- List of Haskell Kata to Update
- List of Java Kata to Update
- List of JavaScript Kata to Update
- List of Kotlin Kata to Update
- List of Lean Kata to Update
- List of Nim Kata to Update
- List of PHP Kata to Update
- List of Python Kata to Update
- List of Racket Kata to Update
- List of Ruby Kata to Update
- List of Rust Kata to Update
- List of Scala Kata to Update
- List of Solidity Kata to Update
- List of Swift Kata to Update
- List of TypeScript Kata to Update