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

10up / wp_mock / 13706662543

06 Mar 2025 07:31PM UTC coverage: 66.446% (+0.1%) from 66.312%
13706662543

push

github

web-flow
Fix: GitHub workflows broken due to outdated versions / OS (#255)

# Summary <!-- Required -->

Updates the versions used for various actions to address:

> Error: This request has been automatically failed because it uses a
deprecated version of `actions/cache:
937d24475`. Please update your workflow
to use v3/v4 of actions/cache to avoid interruptions. Learn more:
https://github.blog/changelog/2024-12-05-notice-of-upcoming-releases-and-breaking-changes-for-github-actions/#actions-cache-v1-v2-and-actions-toolkit-cache-package-closing-down

Also removes deprecated usage of ubuntu-20.04 -- see
https://github.com/actions/runner-images/issues/11101

Also updates the phpstan config to address an unrelated failure. See
https://github.com/10up/wp_mock/pull/255/files#r1983301587

## Details <!-- Optional -->

<!-- Please include a detailed explanation of the changes and/or the
reasoning behind them. -->

## Contributor checklist <!-- Required -->

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you are unsure about any of these, please ask for
clarification. We are here to help! -->

- [ ] I agree to follow this project's [**Code of
Conduct**](https://github.com/10up/.github/blob/trunk/CODE_OF_CONDUCT.md).
- [ ] I have updated the documentation accordingly 
- [ ] I have added tests to cover changes introduced by this pull
request
- [ ] All new and existing tests pass

## Testing <!-- Required -->

- [ ] Code review
- [ ] Checks pass / GH actions run successfully

### Reviewer checklist <!-- Required -->

<!-- The following checklist is for the reviewer: add any steps that may
be relevant while reviewing this pull request -->

- [ ] Code changes review
- [ ] Documentation changes review
- [ ] Unit tests pass
- [ ] Static analysis passes

503 of 757 relevant lines covered (66.45%)

2.66 hits per line

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

50.0
/php/WP_Mock/Hook.php
1
<?php
2

3
namespace WP_Mock;
4

5
use Closure;
6
use PHPUnit\Framework\ExpectationFailedException;
7
use WP_Mock;
8
use WP_Mock\Matcher\AnyInstance;
9
use Mockery\Matcher\Type;
10

11
/**
12
 * Abstract mock representation of a WordPress hook.
13
 *
14
 * @see Action for mocking WordPress action hooks
15
 * @see Filter for mocking WordPress filter hooks
16
 */
17
abstract class Hook
18
{
19
    /** @var string hook name */
20
    protected $name;
21

22
    /** @var array<mixed> collection of processors */
23
    protected $processors = [];
24

25
    /** @var array<string> collection of objects mapped to their Type hashes */
26
    public static array $objects = [];
27

28
    /**
29
     * Hook constructor.
30
     *
31
     * @param string $name hook name
32
     */
33
    public function __construct(string $name)
34
    {
35
        $this->name = $name;
×
36
    }
37

38
    /**
39
     * Gets a string representation of a value.
40
     *
41
     * @param mixed $value
42
     * @return string
43
     */
44
    protected function safe_offset($value): string
45
    {
46
        if (null === $value) {
12✔
47
            return 'null';
1✔
48
        }
49

50
        /**
51
         * The following is to prevent a possible return mismatch when {@see Functions::type()} is used with `callable`,
52
         * and to correctly create safe offsets for processors when expecting that a hook that uses a closure is added via {@see Functions::type(Closure::class)}.
53
         */
54
        $closure = fn() => null;
11✔
55
        if ($value instanceof Closure || Closure::class === $value || (is_string($value) && '<CLOSURE>' === strtoupper($value)) || ($value instanceof Type && $value->match($closure))){
11✔
56
            return '__CLOSURE__';
4✔
57
        }
58

59
        if (is_scalar($value)){
7✔
60
            return (string) $value;
6✔
61
        }
62

63
        if ($value instanceof AnyInstance){
2✔
64
            return (string) $value;
×
65
        }
66

67
        if (is_object($value)){
2✔
68
            if (! $value instanceof Type) {
2✔
69
                $class = get_class($value);
2✔
70

71
                if (isset(static::$objects[$class]) && is_string(static::$objects[$class])) {
2✔
72
                    return static::$objects[$class];
×
73
                }
74
            }
75

76
            return spl_object_hash($value);
2✔
77
        }
78

79
        if (is_array($value)) {
1✔
80
            $parsed = '';
1✔
81

82
            foreach ($value as $k => $v) {
1✔
83
                $k = is_numeric($k) ? '' : $k;
1✔
84
                $parsed .= $k.$this->safe_offset($v);
1✔
85
            }
86

87
            return $parsed;
1✔
88
        }
89

90
        return '';
×
91
    }
92

93
    /** @return Action_Responder|Filter_Responder|HookedCallbackResponder */
94
    public function with()
95
    {
96
        $args      = func_get_args();
×
97
        $responder = $this->new_responder();
×
98

99
        if ($args === array( null )) {
×
100
            $this->processors['argsnull'] = $responder;
×
101
        } else {
102
            $num_args = count($args);
×
103

104
            $processors = &$this->processors;
×
105
            for ($i = 0; $i < $num_args - 1; $i ++) {
×
106
                $arg = $this->safe_offset($args[ $i ]);
×
107

108
                if (! isset($processors[ $arg ])) {
×
109
                    $processors[ $arg ] = array();
×
110
                }
111

112
                $processors = &$processors[ $arg ];
×
113
            }
114

115
            $processors[ $this->safe_offset($args[ $num_args - 1 ]) ] = $responder;
×
116
        }
117

118
        return $responder;
×
119
    }
120

121
    abstract protected function new_responder();
122

123
    /**
124
     * Throws an exception if strict mode is on.
125
     *
126
     * @return void
127
     * @throws ExpectationFailedException
128
     */
129
    protected function strict_check(): void
130
    {
131
        if (WP_Mock::strictMode()) {
×
132
            throw new ExpectationFailedException($this->get_strict_mode_message());
×
133
        }
134
    }
135

136
    /**
137
     * Gets the message to output when the strict mode exception is thrown.
138
     *
139
     * @return string
140
     */
141
    abstract protected function get_strict_mode_message();
142
}
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