mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-17 02:45:16 +02:00
Remove unused DataFilterEvent
This commit is contained in:
parent
0b928fe3e1
commit
bcee92a86c
2 changed files with 0 additions and 140 deletions
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024, the Friendica project
|
||||
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Friendica\Event;
|
||||
|
||||
/**
|
||||
* Allow Event listener to modify data.
|
||||
*/
|
||||
final class DataFilterEvent
|
||||
{
|
||||
private string $name;
|
||||
|
||||
/** @var string|array */
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* @param string|array $data
|
||||
*/
|
||||
public function __construct(string $name, $data)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $data
|
||||
*
|
||||
* @throws \InvalidArgumentException If $data is a string but the original data was an array and vice versa.
|
||||
*/
|
||||
public function setData($data): void
|
||||
{
|
||||
if (is_string($this->data) && is_array($data)) {
|
||||
throw new \InvalidArgumentException('Argument #1 ($data) must be of type string, array given');
|
||||
}
|
||||
|
||||
if (is_array($this->data) && is_string($data)) {
|
||||
throw new \InvalidArgumentException('Argument #1 ($data) must be of type array, string given');
|
||||
}
|
||||
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024, the Friendica project
|
||||
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Friendica\Test\Unit\Event;
|
||||
|
||||
use Friendica\Event\DataFilterEvent;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DataFilterEventTest extends TestCase
|
||||
{
|
||||
public function testGetNameReturnsName(): void
|
||||
{
|
||||
$event = new DataFilterEvent('test', []);
|
||||
|
||||
$this->assertSame('test', $event->getName());
|
||||
}
|
||||
|
||||
public function testGetDataReturnsArray(): void
|
||||
{
|
||||
$data = ['data' => 'original'];
|
||||
|
||||
$event = new DataFilterEvent('test', $data);
|
||||
|
||||
$this->assertSame($data, $event->getData());
|
||||
}
|
||||
|
||||
public function testGetDataReturnsString(): void
|
||||
{
|
||||
$data = 'original';
|
||||
|
||||
$event = new DataFilterEvent('test', $data);
|
||||
|
||||
$this->assertSame($data, $event->getData());
|
||||
}
|
||||
|
||||
public function testSetDataUpdatesData(): void
|
||||
{
|
||||
$data = ['data' => 'original'];
|
||||
|
||||
$event = new DataFilterEvent('test', $data);
|
||||
|
||||
$expected = ['data' => 'updated'];
|
||||
|
||||
$event->setData($expected);
|
||||
|
||||
$this->assertSame($expected, $event->getData());
|
||||
}
|
||||
|
||||
public function testSetDataWithStringThrowsException(): void
|
||||
{
|
||||
$data = ['data' => 'original'];
|
||||
|
||||
$event = new DataFilterEvent('test', $data);
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Argument #1 ($data) must be of type array, string given');
|
||||
|
||||
$event->setData('try to set a string instead of an array');
|
||||
}
|
||||
|
||||
public function testSetDataWithArrayThrowsException(): void
|
||||
{
|
||||
$data = 'original data';
|
||||
|
||||
$event = new DataFilterEvent('test', $data);
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Argument #1 ($data) must be of type string, array given');
|
||||
|
||||
$event->setData(['try to set an array instead of a string']);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue