• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RonasIT / laravel-helpers / 3929967872

pending completion
3929967872

Pull #52

github

GitHub
Merge e8557eed9 into 71346419b
Pull Request #52: feat: update http request service to use easy mock;

32 of 32 new or added lines in 3 files covered. (100.0%)

150 of 910 relevant lines covered (16.48%)

1.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Traits/MockClassTrait.php
1
<?php
2

3
namespace RonasIT\Support\Traits;
4

5
trait MockClassTrait
6
{
7
    /**
8
     * Mock selected class. Call chain should looks like:
9
     *
10
     * [
11
     *     [
12
     *         'method' => 'yourMethod',
13
     *         'arguments' => ['firstArgumentValue', 2, true],
14
     *         'result' => 'result_fixture.json'
15
     *     ]
16
     * ]
17
     *
18
     * @param string $class
19
     * @param array $callChain
20
     */
21
    public function mockClass(string $class, array $callChain): void
22
    {
23
        $methodsCalls = collect($callChain)->groupBy('method');
×
24

25
        $mock = $this
×
26
            ->getMockBuilder($class)
×
27
            ->onlyMethods($methodsCalls->keys()->toArray())
×
28
            ->getMock();
×
29

30
        $methodsCalls->each(function ($calls, $method) use (&$mock) {
×
31
            $mock
×
32
                ->expects($this->exactly($calls->count()))
×
33
                ->method($method)
×
34
                ->withConsecutive(...$calls->map(function ($call) {
×
35
                    return $call['arguments'];
×
36
                })->toArray())
×
37
                ->willReturnOnConsecutiveCalls(...$calls->map(function ($call) {
×
38
                    return $call['result'];
×
39
                })->toArray());
×
40
        });
×
41

42
        $this->app->instance($class, $mock);
×
43
    }
44
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc