Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 7d7492b

Browse files
committed
Add a test to demonstrate #270
1 parent 211a329 commit 7d7492b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/HasLdapUserTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace Adldap\Laravel\Tests;
3+
4+
use Adldap\Laravel\Tests\Models\User as EloquentUser;
5+
use Adldap\Laravel\Traits\HasLdapUser;
6+
use Adldap\Models\User as LdapUser;
7+
8+
class HasLdapUserTest extends \PHPUnit_Framework_TestCase
9+
{
10+
public function testSetLdapUserSetsUserOnModel()
11+
{
12+
$user = $this->createEloquentUser();
13+
$ldapUser = \Mockery::mock(LdapUser::class);
14+
15+
$user->setLdapUser($ldapUser);
16+
17+
$this->assertEquals($ldapUser, $user->ldap);
18+
}
19+
20+
21+
public function testSetLdapUserWithNull()
22+
{
23+
$user = $this->createEloquentUser();
24+
25+
$user->setLdapUser(null);
26+
27+
$this->assertNull($user->ldap);
28+
}
29+
30+
/**
31+
* @return HasLdapUser
32+
*/
33+
private function createEloquentUser()
34+
{
35+
$user = new EloquentUser();
36+
37+
if (! array_key_exists(HasLdapUser::class, class_uses(EloquentUser::class))) {
38+
$this->fail('User model does not use ' . HasLdapUser::class);
39+
}
40+
41+
return $user;
42+
}
43+
}

0 commit comments

Comments
 (0)