Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Latest commit

 

History

History
185 lines (140 loc) · 7.48 KB

MIGRATING.md

File metadata and controls

185 lines (140 loc) · 7.48 KB

Migration guide

Migrating from 5.x to 6.x

The Phony 6.x release drops support for PHP 7.3 and 7.4. If you only need to support PHP 8.0 or later, then it is recommended that you upgrade to Phony 6.x. If you still need to support PHP 7.3 or 7.4, then you are free to continue using the 5.x version of Phony.

Migrating from 4.x to 5.x

The Phony 5.x release drops support for PHP 7.2. If you only need to support PHP 7.3 or later, then it is recommended that you upgrade to Phony 5.x. If you still need to support PHP 7.2, then you are free to continue using the 4.x version of Phony.

Migrating from 3.x to 4.x

The Phony 4.x release drops support for PHP 7.1. If you only need to support PHP 7.2 or later, then it is recommended that you upgrade to Phony 4.x. If you still need to support PHP 7.1, then you are free to continue using the 3.x version of Phony.

Migrating from 2.x to 3.x

The 3.x release only supports PHP 7.1 or later

The Phony 3.x release drops support for PHP 7.0. If you only need to support PHP 7.1 or later, then it is recommended that you upgrade to Phony 3.x. If you still need to support PHP 7.0, then you are free to continue using the 2.x version of Phony.

Utilization of void and nullable type hints

Where possible, the entire Phony 3.x API now takes advantage of nullable types and void functions.

In terms of usage, this only affects setUseColor(), which had an undocumented default value of null for its only argument. This function now requires an explicit null value if you wish to set color usage based upon the current environment.

Utilization of relaxed keywords

The handle->clazz() method was renamed to handle->class(), since PHP 7 now allows class as a method name.

Migrating from 1.x to 2.x

The 2.x release only supports PHP 7

The Phony 2.x release is primarily about dropping support for PHP 5 and HHVM. If you only need to support PHP 7, then it is recommended that you upgrade to Phony 2.x. If you still need to support PHP 5, then you are free to continue using the 1.x version of Phony.

More type hints, less squishy types

Where possible, the entire Phony 2.x API has introduced scalar type hints. If your tests use strict typing, and you are passing an incorrect type to Phony, an error will now be thrown.

In addition; some values that were previously represented as a scalar value OR null, have been changed to use a scalar value only:

Dynamic order verification functions removed

The following functions were removed from the top-level API because they have been made redundant:

In order to perform dynamic order verification under Phony 2.x, simply use the ... operator:

$events = [$spyA->called(), $spyB->called()];

inOrder(...$events);
inOrderSequence(...$events);
anyOrder(...$events);
anyOrderSequence(...$events);

Improved "self" value behavior for function-level stubs

By default, a function-level stub's "self" value is now set to the stub itself, rather than the callback wrapped by the stub. This was changed to improve the functionality of stubs using magic "self" values in combination with recursion.

When the "self" value is set to the wrapped callback, recursion requires passing $phonySelf as the first argument when calling back into $phonySelf. But with the "self" value set to the stub itself, this is no longer necessary, and recursive functions become simpler:

$factorial = stub(
    function ($phonySelf, $n) {
        if (0 === $n) {
            return 1;
        }

        // with the "self" value set to the stub itself (2.x default):
        return $n * $phonySelf($n - 1);

        // with the "self" value set to the wrapped callback (1.x default):
        return $n * $phonySelf($phonySelf, $n - 1);
    }
);
$factorial->forwards();

echo $factorial(0); // outputs '1'
echo $factorial(1); // outputs '1'
echo $factorial(2); // outputs '2'
echo $factorial(3); // outputs '6'
echo $factorial(4); // outputs '24'
echo $factorial(5); // outputs '120'

Stubs associated with a mock are not affected, and will continue to have their "self" value default to the mock instance.