blob: 70640af95738e27397ce9181e96c1fa6d78391ce [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2
3namespace LdapRecord\Testing;
4
5use LdapRecord\Container;
6
7class DirectoryFake
8{
9 /**
10 * Setup the fake connection.
11 *
12 * @param string|null $name
13 *
14 * @throws \LdapRecord\ContainerException
15 *
16 * @return ConnectionFake
17 */
18 public static function setup($name = null)
19 {
20 $connection = Container::getConnection($name);
21
22 $fake = static::makeConnectionFake(
23 $connection->getConfiguration()->all()
24 );
25
26 // Replace the connection with a fake.
27 Container::addConnection($fake, $name);
28
29 return $fake;
30 }
31
32 /**
33 * Reset the container.
34 *
35 * @return void
36 */
37 public static function tearDown()
38 {
39 Container::reset();
40 }
41
42 /**
43 * Make a connection fake.
44 *
45 * @param array $config
46 *
47 * @return ConnectionFake
48 */
49 public static function makeConnectionFake(array $config = [])
50 {
51 return ConnectionFake::make($config)->shouldBeConnected();
52 }
53}