Skip to content

Commit c314c6b

Browse files
committed
Add SearchEngines::setEngines method
1 parent 0977b74 commit c314c6b

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/SearchEngines.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ public function setEngine(string $name, string $url) : static
128128
return $this;
129129
}
130130

131+
/**
132+
* Set multiple search engines at once.
133+
*
134+
* @param array<string,string> $engines
135+
*/
136+
public function setEngines(array $engines) : static
137+
{
138+
foreach ($engines as $name => $url) {
139+
$this->setEngine($name, $url);
140+
}
141+
return $this;
142+
}
143+
131144
/**
132145
* Returns the base URL of an engine; throws exception if it does not exist.
133146
*

tests/SearchEnginesTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ public function testSetEngineWithInvalidUrl() : void
6363
$this->searchEngines->setEngine('foo', 'foo.com');
6464
}
6565

66+
public function testSetEngines() : void
67+
{
68+
$engines = $this->searchEngines->getEngines();
69+
self::assertSame('https://www.google.com/search?q=', $engines['google']);
70+
self::assertArrayHasKey('google', $engines);
71+
self::assertArrayNotHasKey('foo', $engines);
72+
$this->searchEngines->setEngines([
73+
'foo' => 'https://foo.com',
74+
'google' => 'https://bar.com',
75+
]);
76+
$engines = $this->searchEngines->getEngines();
77+
self::assertSame('https://foo.com', $engines['foo']);
78+
self::assertSame('https://bar.com', $engines['google']);
79+
}
80+
6681
public function testGetUrl() : void
6782
{
6883
self::assertIsString($this->searchEngines->getUrl('google'));

0 commit comments

Comments
 (0)