How to use HigherOrderMessage class

Best Mockery code snippet using .HigherOrderMessage

Run Mockery automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

HigherOrderMessageCollection.php

Source: HigherOrderMessageCollection.php Github

copy
1<?php
2
3declare(strict_types=1);
4
5namespace Pest\Support;
6
7/**
8 * @internal
9 */
10final class HigherOrderMessageCollection
11{
12    /**
13     * @var array<int, HigherOrderMessage>
14     */
15    private $messages = [];
16
17    /**
18     * Adds a new higher order message to the collection.
19     *
20     * @param array<int, mixed>|null $arguments
21     */
22    public function add(string $filename, int $line, string $name, array $arguments = null): void
23    {
24        $this->messages[] = new HigherOrderMessage($filename, $line, $name, $arguments);
25    }
26
27    /**
28     * Adds a new higher order message to the collection if the callable condition is does not return false.
29     *
30     * @param array<int, mixed>|null $arguments
31     */
32    public function addWhen(callable $condition, string $filename, int $line, string $name, array $arguments = null): void
33    {
34        $this->messages[] = (new HigherOrderMessage($filename, $line, $name, $arguments))->when($condition);
35    }
36
37    /**
38     * Proxy all the messages starting from the target.
39     */
40    public function chain(object $target): void
41    {
42        foreach ($this->messages as $message) {
43            $target = $message->call($target) ?? $target;
44        }
45    }
46
47    /**
48     * Proxy all the messages to the target.
49     */
50    public function proxy(object $target): void
51    {
52        foreach ($this->messages as $message) {
53            $message->call($target);
54        }
55    }
56
57    /**
58     * Count the number of messages with the given name.
59     *
60     * @param string $name A higher order message name (usually a method name)
61     */
62    public function count(string $name): int
63    {
64        return array_reduce(
65            $this->messages,
66            static function (int $total, HigherOrderMessage $message) use ($name): int {
67                return $total + (int) ($name === $message->name);
68            },
69            0,
70        );
71    }
72}
73
Full Screen

HigherOrderMessageTest.php

Source: HigherOrderMessageTest.php Github

copy
1<?php
2
3/*
4 * This file is part of the PHP-UNDERSCORE package.
5 *
6 * (c) Jitendra Adhikari <[email protected]>
7 *     <https://github.com/adhocore>
8 *
9 * Licensed under MIT license.
10 */
11
12namespace Ahc\Underscore\Test;
13
14use Ahc\Underscore\HigherOrderMessage;
15use PHPUnit\Framework\TestCase as TestCase;
16
17class HOM
18{
19    public $b = 'B';
20
21    public function a()
22    {
23        return 'A';
24    }
25}
26
27/**
28 * Auto generated by `phint test`.
29 */
30class HigherOrderMessageTest extends TestCase
31{
32    /**
33     * @var HigherOrderMessage
34     */
35    protected $hom1;
36
37    /**
38     * @var HigherOrderMessage
39     */
40    protected $hom2;
41
42    public function setUp()
43    {
44        parent::setUp();
45
46        $this->hom1 = new HigherOrderMessage(
47            underscore([['a' => 1, 'b' => 2]]),
48            'map'
49        );
50
51        $this->hom2 = new HigherOrderMessage(
52            underscore([new HOM]),
53            'map'
54        );
55    }
56
57    public function test_call()
58    {
59        $actual = $this->hom2->a()->get();
60
61        $this->assertSame(['A'], $actual);
62    }
63
64    public function test_get()
65    {
66        $actual = $this->hom1->b->get();
67
68        $this->assertSame([2], $actual);
69
70        $actual = $this->hom2->b->get();
71
72        $this->assertSame(['B'], $actual);
73    }
74}
75
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in HigherOrderMessage

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)