Skip to content

Commit

Permalink
Merge pull request #7 from lexidor/hhast-lint
Browse files Browse the repository at this point in the history
Hhast lint
  • Loading branch information
lexidor authored Dec 6, 2019
2 parents 1740b25 + e0711a4 commit 4894d1d
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 49 deletions.
10 changes: 9 additions & 1 deletion hhast-lint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"roots": [ "src/", "tests/" ],
"builtinLinters": "all",
"disableAllAutoFixes": true
"disableAllAutoFixes": true,
"overrides": [
{
"patterns": ["*"],
"disabledLinters": [
"Facebook\\HHAST\\Linters\\MustUseOverrideAttributeLinter"
]
}
]
}
32 changes: 16 additions & 16 deletions src/MockManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace Hammock;

use Hammock\Exceptions\{HammockException, PassThroughException};
use type Hammock\Exceptions\{HammockException, PassThroughException};
use function Hammock\get_declaring_class_name;
use namespace HH\Lib\{C, Dict, Vec};
use namespace HH\Lib\{C, Dict, Str, Vec};
use type Hammock\{MockCallback, InterceptedCall};

class MockManager {
Expand Down Expand Up @@ -48,7 +48,7 @@ classname<T> $className,
C\contains_key(self::$objectMethodMocks, $mockKey)
) {
throw new HammockException(
"The method `{$mockKey}` has already been mocked.",
Str\format("The method `%s` has already been mocked.", $mockKey),
);
}

Expand All @@ -74,13 +74,13 @@ public static function mockGlobalFunction(
): void {
if (!\function_exists($globalFunctionName)) {
throw new HammockException(
"The function `{$globalFunctionName}` does not exist.",
Str\format("The function `%s` does not exist.", $globalFunctionName),
);
}

if (C\contains_key(self::$globalFunctionMocks, $globalFunctionName)) {
throw new HammockException(
"The function `{$globalFunctionName}` has already been mocked.",
Str\format("The function `%s` has already been mocked.", $globalFunctionName),
);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public static function mockObjectMethod<T>(

if (C\contains_key(self::$classMethodMocks, $mockKey)) {
throw new HammockException(
"The method `{$mockKey}` already has a class-level mock.",
Str\format("The method `%s` already has a class-level mock.", $mockKey),
);
}

Expand All @@ -120,7 +120,7 @@ public static function mockObjectMethod<T>(

if (C\contains_key(self::$objectMethodMocks[$mockKey], $objectHash)) {
throw new HammockException(
"The method `{$mockKey}` has already been mocked for this object.",
Str\format("The method `%s` has already been mocked for this object.", $mockKey),
);
}

Expand All @@ -144,7 +144,7 @@ public static function getGlobalFunctionCalls(
): vec<InterceptedCall> {
if (!C\contains_key(self::$globalFunctionMocks, $globalFunctionName)) {
throw new HammockException(
"The function `{$globalFunctionName}` has not been mocked.",
Str\format("The function `%s` has not been mocked.", $globalFunctionName),
);
}

Expand Down Expand Up @@ -178,7 +178,7 @@ public static function unmockGlobalFunction(
): void {
if (!C\contains_key(self::$globalFunctionMocks, $globalFunctionName)) {
throw new HammockException(
"The function `{$globalFunctionName}` has not been mocked.",
Str\format("The function `%s` has not been mocked.", $globalFunctionName),
);
}

Expand Down Expand Up @@ -242,7 +242,7 @@ protected static function initializeObjectLevelMock(string $mockKey): void {
(mixed $object, vec<mixed> $args): mixed ==> {
if ($object === null) {
throw new HammockException(
"The static method `{$mockKey}` was mocked through an object-level mock. Static methods may only be mocked by class-level mocks.",
Str\format("The static method `%s` was mocked through an object-level mock. Static methods may only be mocked by class-level mocks.", $mockKey)
);
}

Expand Down Expand Up @@ -271,7 +271,7 @@ classname<T> $className,

if (!C\contains_key(self::$classMethodMocks, $mockKey)) {
throw new HammockException(
"The method `{$mockKey}` does not have a class-level mock.",
Str\format("The method `%s` does not have a class-level mock.", $mockKey),
);
}

Expand All @@ -286,15 +286,15 @@ protected static function getValidatedObjectMethodMockKeyAndObjectHash<T>(

if (!C\contains_key(self::$objectMethodMocks, $mockKey)) {
throw new HammockException(
"The method `{$mockKey}` does not have an object-level mock.",
Str\format("The method `%s` does not have an object-level mock.", $mockKey),
);
}

$objectHash = self::hashObject($object);

if (!C\contains_key(self::$objectMethodMocks[$mockKey], $objectHash)) {
throw new HammockException(
"The method `{$mockKey}` has not been mocked for this object.",
Str\format("The method `%s` has not been mocked for this object.", $mockKey),
);
}

Expand Down Expand Up @@ -364,7 +364,7 @@ classname<T> $className,

if ($shouldMatchDeclaringClassName && $declaringClassName !== $className) {
throw new HammockException(
"The method `{$className}::{$methodName}` is declared in `{$declaringClassName}`. Please use `{$declaringClassName}::{$methodName}` instead.",
Str\format("The method `%s::%s` is declared in `%s`. Please use `%s::%s` instead.", $className, $methodName, $declaringClassName, $declaringClassName, $methodName),
);
}

Expand All @@ -380,15 +380,15 @@ protected static function getFullyQualifiedObjectMethodName<T>(
// We can enforce static constraints by using `T as nonnull`.
if ($object === null) {
throw new HammockException(
"The method `{$methodName}` cannot be resolved for `null`.",
Str\format("The method `%s` cannot be resolved for `null`.", $methodName),
);
}

$className = \get_class($object);

if ($className === false) {
throw new HammockException(
"The method `{$methodName}` cannot be resolved for a non-object.",
Str\format("The method `%s` cannot be resolved for a non-object.", $methodName),
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Mocks/FunctionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Hammock\Mocks;

use Hammock\InterceptedCall;
use Hammock\Interfaces\IFunctionMock;
use Hammock\Persistent\Mocks\PersistentFunctionMock;
use type Hammock\InterceptedCall;
use type Hammock\Interfaces\IFunctionMock;
use type Hammock\Persistent\Mocks\PersistentFunctionMock;

class FunctionMock implements \IDisposable, IFunctionMock {
public function __construct(protected PersistentFunctionMock $delegate) {}
Expand Down
6 changes: 3 additions & 3 deletions src/Mocks/MethodMockContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Hammock\Mocks;

use Hammock\Interfaces\{IFunctionMock, IMethodMockContainer};
use Hammock\MockCallback;
use Hammock\Persistent\Mocks\PersistentMethodMockContainer;
use type Hammock\Interfaces\{IFunctionMock, IMethodMockContainer};
use type Hammock\MockCallback;
use type Hammock\Persistent\Mocks\PersistentMethodMockContainer;

class MethodMockContainer implements \IDisposable, IMethodMockContainer {
public function __construct(
Expand Down
4 changes: 3 additions & 1 deletion src/Persistent/Mocks/ClassMethodMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Hammock\Persistent\Mocks;

use Hammock\MockManager;
use type Hammock\MockManager;
use type Hammock\{InterceptedCall, MockCallback};

class ClassMethodMock<T> extends PersistentFunctionMock {
Expand All @@ -14,11 +14,13 @@ public function __construct(
MockManager::mockClassMethod($className, $methodName, $callback);
}

<<__Override>>
protected function actuallyGetCalls(): vec<InterceptedCall> {
return
MockManager::getClassMethodCalls($this->className, $this->methodName);
}

<<__Override>>
protected function actuallyDeactivate(): void {
MockManager::unmockClassMethod($this->className, $this->methodName);
}
Expand Down
1 change: 1 addition & 0 deletions src/Persistent/Mocks/ClassMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class ClassMock<T> extends PersistentMethodMockContainer {
public function __construct(protected classname<T> $className) {}

<<__Override>>
protected function createMethodMock(
string $methodName,
MockCallback $callback,
Expand Down
4 changes: 3 additions & 1 deletion src/Persistent/Mocks/GlobalFunctionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Hammock\Persistent\Mocks;

use Hammock\MockManager;
use type Hammock\MockManager;
use type Hammock\{InterceptedCall, MockCallback};

class GlobalFunctionMock extends PersistentFunctionMock {
Expand All @@ -13,10 +13,12 @@ public function __construct(
MockManager::mockGlobalFunction($globalFunctionName, $callback);
}

<<__Override>>
protected function actuallyGetCalls(): vec<InterceptedCall> {
return MockManager::getGlobalFunctionCalls($this->globalFunctionName);
}

<<__Override>>
protected function actuallyDeactivate(): void {
MockManager::unmockGlobalFunction($this->globalFunctionName);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Persistent/Mocks/ObjectMethodMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Hammock\Persistent\Mocks;

use Hammock\MockManager;
use type Hammock\MockManager;
use type Hammock\{InterceptedCall, MockCallback};

class ObjectMethodMock<T> extends PersistentFunctionMock {
Expand All @@ -14,10 +14,12 @@ public function __construct(
MockManager::mockObjectMethod($object, $methodName, $callback);
}

<<__Override>>
protected function actuallyGetCalls(): vec<InterceptedCall> {
return MockManager::getObjectMethodCalls($this->object, $this->methodName);
}

<<__Override>>
protected function actuallyDeactivate(): void {
MockManager::unmockObjectMethod($this->object, $this->methodName);
}
Expand Down
1 change: 1 addition & 0 deletions src/Persistent/Mocks/ObjectMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class ObjectMock<T> extends PersistentMethodMockContainer {
public function __construct(protected T $object) {}

<<__Override>>
protected function createMethodMock(
string $methodName,
MockCallback $callback,
Expand Down
8 changes: 4 additions & 4 deletions src/Persistent/Mocks/PersistentFunctionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Hammock\Persistent\Mocks;

use HH\Lib\C;
use Hammock\Exceptions\HammockException;
use Hammock\Interfaces\{IFunctionMock, IDeactivatable};
use namespace HH\Lib\{C, Str};
use type Hammock\Exceptions\HammockException;
use type Hammock\Interfaces\{IFunctionMock, IDeactivatable};
use type Hammock\InterceptedCall;

abstract class PersistentFunctionMock implements IFunctionMock, IDeactivatable {
Expand Down Expand Up @@ -32,7 +32,7 @@ public function getArgsForCall(int $i): vec<mixed> {

if ($i < 0 || $i >= $numCalls) {
throw new HammockException(
"Cannot access index {$i} of calls (total number of calls: {$numCalls}).",
Str\format("Cannot access index %d of calls (total number of calls: %d).", $i, $numCalls),
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Persistent/Mocks/PersistentMethodMockContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Hammock\Persistent\Mocks;

use Hammock\Exceptions\HammockException;
use Hammock\Interfaces\{IFunctionMock, IMethodMockContainer, IDeactivatable};
use type Hammock\Exceptions\HammockException;
use type Hammock\Interfaces\{IFunctionMock, IMethodMockContainer, IDeactivatable};
use function Hammock\{get_noop_callback, get_spy_callback};
use namespace HH\Lib\{C, Dict};
use namespace HH\Lib\{C, Str};
use type Hammock\MockCallback;

abstract class PersistentMethodMockContainer
Expand Down Expand Up @@ -40,7 +40,7 @@ public function noopMethod(string $methodName): IFunctionMock {
public function getMethodMock(string $methodName): IFunctionMock {
if (!C\contains_key($this->methodMocks, $methodName)) {
throw new HammockException(
"There is no mock for the method `{$methodName}`.",
Str\format("There is no mock for the method `%s`.", $methodName),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Persistent/PersistentMockRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Hammock\Persistent;

use Hammock\Interfaces\IDeactivatable;
use type Hammock\Interfaces\IDeactivatable;

class PersistentMockRegistry {
protected static vec<IDeactivatable> $registry = vec[];
Expand Down
2 changes: 1 addition & 1 deletion src/Persistent/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Hammock\Persistent;

use Hammock\Persistent\Mocks\{
use type Hammock\Persistent\Mocks\{
ClassMethodMock,
ClassMock,
GlobalFunctionMock,
Expand Down
4 changes: 2 additions & 2 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Hammock;

use Hammock\Persistent\Mocks\{
use type Hammock\Persistent\Mocks\{
ClassMethodMock,
ClassMock,
GlobalFunctionMock,
ObjectMethodMock,
ObjectMock,
};

use Hammock\Mocks\{MethodMockContainer, FunctionMock};
use type Hammock\Mocks\{MethodMockContainer, FunctionMock};
use function Hammock\{get_noop_callback, get_spy_callback};
use type Hammock\MockCallback;

Expand Down
5 changes: 3 additions & 2 deletions src/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Hammock;

use Hammock\Exceptions\{HammockException, PassThroughException};
use namespace HH\Lib\Str;
use type Hammock\Exceptions\{HammockException, PassThroughException};
use type Hammock\MockCallback;

function get_spy_callback(): MockCallback {
Expand All @@ -21,7 +22,7 @@ classname<T> $className,
): classname<Td> {
if (!\method_exists($className, $methodName)) {
throw new HammockException(
"The method `{$className}::{$methodName}` does not exist.",
Str\format("The method `%s::%s` does not exist.", $className, $methodName),
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/HammockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Hammock;

use Facebook\HackTest\HackTest;
use Hammock\Exceptions\HammockException;
use Hammock\Fixtures\{AnotherClass, ChildClass, TestClass};
use type Facebook\HackTest\HackTest;
use type Hammock\Exceptions\HammockException;
use type Hammock\Fixtures\{AnotherClass, ChildClass, TestClass};
use function Facebook\FBExpect\expect;
use function Hammock\Fixtures\{return_input, return_inputs};

Expand Down
11 changes: 5 additions & 6 deletions tests/PersistentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace Hammock;

use Facebook\HackTest\HackTest;
use Hammock\Exceptions\HammockException;
use Hammock\Fixtures\{AnotherClass, ChildClass, TestClass};
use Hammock\Interfaces\IFunctionMock;
use Hammock\Persistent\Mocks\{PersistentFunctionMock};
use type Facebook\HackTest\HackTest;
use type Hammock\Exceptions\HammockException;
use type Hammock\Fixtures\{ChildClass, TestClass};
use type Hammock\Persistent\Mocks\{PersistentFunctionMock};
use function Facebook\FBExpect\expect;
use function Hammock\Fixtures\{return_input, return_inputs};
use function Hammock\Fixtures\return_input;
use namespace Hammock\Persistent;

class PersistentTest extends HackTest {
Expand Down

0 comments on commit 4894d1d

Please sign in to comment.