Skip to content

Commit

Permalink
assertSame instead of assertEquals (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
TavoNiievez authored Jan 3, 2022
1 parent b15254b commit d82b6e5
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ Let's redefine static methods and verify their calls at runtime.

function testTableName()
{
$this->assertEquals('users', UserModel::tableName());
$this->assertSame('users', UserModel::tableName());
$userModel = test::double('UserModel', ['tableName' => 'my_users']);
$this->assertEquals('my_users', UserModel::tableName());
$this->assertSame('my_users', UserModel::tableName());
$userModel->verifyInvoked('tableName');
}
```
Expand Down Expand Up @@ -83,7 +83,7 @@ function testUserCreate()
$user = test::double('User', ['save' => null]);
$service = new UserService;
$service->createUserByName('davert');
$this->assertEquals('davert', $user->getName());
$this->assertSame('davert', $user->getName());
$user->verifyInvoked('save');
}
```
Expand All @@ -99,10 +99,10 @@ function testUserCreate()
$AR = test::double('ActiveRecord', ['save' => null]));
test::double('User', ['findByNameAndEmail' => new User(['name' => 'jon'])]));
$user = User::findByNameAndEmail('jon','[email protected]'); // magic method
$this->assertEquals('jon', $user->getName());
$this->assertSame('jon', $user->getName());
$user->save(['name' => 'miles']); // ActiveRecord->save did not hit database
$AR->verifyInvoked('save');
$this->assertEquals('miles', $user->getName());
$this->assertSame('miles', $user->getName());
}
```

Expand All @@ -113,7 +113,7 @@ function testUserCreate()

namespace demo;
test::func('demo', 'time', 'now');
$this->assertEquals('now', time());
$this->assertSame('now', time());
```

#### Beautifully simple
Expand All @@ -126,7 +126,7 @@ Only 4 methods are necessary for method call verification and one method to defi
function testSimpleStubAndMock()
{
$user = test::double(new User, ['getName' => 'davert']);
$this->assertEquals('davert', $user->getName());
$this->assertSame('davert', $user->getName());
$user->verifyInvoked('getName');
$user->verifyInvokedOnce('getName');
$user->verifyNeverInvoked('setName');
Expand Down
2 changes: 1 addition & 1 deletion docs/InstanceProxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Contains verification methods and `class` property that points to `ClassProxy`.
$user = new User(['name' => 'davert']);
$user = test::double(new User);
// now $user is a proxy class of user
$this->assertEquals('davert', $user->getName()); // success
$this->assertSame('davert', $user->getName()); // success
$user->verifyInvoked('getName'); // success
$this->assertInstanceOf('User', $user); // fail
```
Expand Down
2 changes: 1 addition & 1 deletion docs/Test.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ You can create instances of undefined classes and play with them:
$user = test::spec('User')->construct();
$user->setName('davert');
$user->setNumPosts(count($user->getPosts()));
$this->assertEquals('davert', $user->getName()); // fail
$this->assertSame('davert', $user->getName()); // fail
```

The test will be executed normally and will fail at the first assertion.
Expand Down
2 changes: 1 addition & 1 deletion src/AspectMock/Proxy/InstanceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* $user = new User(['name' => 'davert']);
* $user = test::double(new User);
* // now $user is a proxy class of user
* $this->assertEquals('davert', $user->getName()); // success
* $this->assertSame('davert', $user->getName()); // success
* $user->verifyInvoked('getName'); // success
* $this->assertInstanceOf('User', $user); // fail
* ```
Expand Down
2 changes: 1 addition & 1 deletion src/AspectMock/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function double($classOrObject, array $params = array())
* $user = test::spec('User')->construct();
* $user->setName('davert');
* $user->setNumPosts(count($user->getPosts()));
* $this->assertEquals('davert', $user->getName()); // fail
* $this->assertSame('davert', $user->getName()); // fail
* ```
*
* The test will be executed normally and will fail at the first assertion.
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/AccessDemoClassesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class AccessDemoClassesTest extends TestCase
public function testUserModel()
{
$user = new UserModel(['name' => 'davert']);
$this->assertEquals('davert', $user->getName());
$this->assertSame('davert', $user->getName());
}

public function testUserService()
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public function testSaveAgain()
double::registerClass('\demo\UserModel', ['save' => "saved!"]);
$user = new UserModel();
$saved = $user->save();
$this->assertEquals('saved!', $saved);
$this->assertSame('saved!', $saved);
}

public function testCallback()
{
double::registerClass('\demo\UserModel', ['save' => function () { return $this->name; }]);
$user = new UserModel(['name' => 'davert']);
$name = $user->save();
$this->assertEquals('davert', $name);
$this->assertSame('davert', $name);

}

Expand All @@ -45,7 +45,7 @@ public function testBindSelfCallback()
return UserModel::$topSecret;
}]);
$topSecret = UserModel::getTopSecret();
$this->assertEquals('awesome', $topSecret);
$this->assertSame('awesome', $topSecret);
}

public function testObjectInstance()
Expand All @@ -57,51 +57,51 @@ public function testObjectInstance()

public function testStaticAccess()
{
$this->assertEquals('users', UserModel::tableName());
$this->assertSame('users', UserModel::tableName());
double::registerClass('\demo\UserModel', ['tableName' => 'my_users']);
$this->assertEquals('my_users', UserModel::tableName());
$this->assertSame('my_users', UserModel::tableName());
}

public function testInheritance()
{
double::registerClass('\demo\UserModel', ['save' => false]);
$admin = new AdminUserModel();
$admin->save();
$this->assertEquals('Admin_111', $admin->getName());
$this->assertSame('Admin_111', $admin->getName());
}

public function testMagic()
{
double::registerClass('\demo\UserService', ['rename' => 'David Copperfield']);
$admin = new UserService();
$this->assertEquals('David Copperfield', $admin->rename());
$this->assertSame('David Copperfield', $admin->rename());

}

public function testMagicOfInheritedClass()
{
double::registerClass('\demo\AdminUserModel', ['renameUser' => 'David Copperfield']);
$admin = new AdminUserModel();
$this->assertEquals('David Copperfield', $admin->renameUser());
$this->assertSame('David Copperfield', $admin->renameUser());
}

public function testMagicStaticInherited()
{
double::registerClass('\demo\AdminUserModel', ['defaultRole' => 'admin']);
$this->assertEquals('admin', AdminUserModel::defaultRole());
$this->assertSame('admin', AdminUserModel::defaultRole());
}

public function testMagicStatic()
{
double::registerClass('\demo\UserModel', ['defaultRole' => 'admin']);
$this->assertEquals('admin', UserModel::defaultRole());
$this->assertSame('admin', UserModel::defaultRole());
}

// public function testStubFunctionCall()
// {
// double::registerFunc('file_put_contents', 'Done');
// $user = new UserModel();
// $user->setName('David Bovie');
// $this->assertEquals('Done', $user->dump());
// $this->assertSame('Done', $user->dump());
// }
}
8 changes: 4 additions & 4 deletions tests/unit/testDoubleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ public function testPhp7Features()
$this->assertTrue($obj->arraySth([]));
$str = 'hello';
$this->assertTrue($obj->variadicStringSthByRef($str, $str));
$this->assertEquals('hey', $obj->stringRth($str));
$this->assertEquals(12.2, $obj->floatRth(12.12));
$this->assertSame('hey', $obj->stringRth($str));
$this->assertSame(12.2, $obj->floatRth(12.12));
$this->assertTrue($obj->boolRth(false));
$this->assertEquals(12, $obj->intRth(15));
$this->assertSame(12, $obj->intRth(15));
//$this->assertInternalType('callable', $obj->callableRth(function() {}));
$this->assertEquals([1], $obj->arrayRth([]));
$this->assertSame([1], $obj->arrayRth([]));
$this->assertInstanceOf('Exception', $obj->exceptionRth(new Exception('ups')));
}
}

0 comments on commit d82b6e5

Please sign in to comment.