Getting started on attachment retrieval
parent
999cb74865
commit
3cec244e15
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Attachments;
|
||||||
|
|
||||||
|
|
||||||
|
use DataAccess\Attachments\AttachmentGateway;
|
||||||
|
use DataAccess\Files\FileReader;
|
||||||
|
|
||||||
|
class AttachmentRetriever {
|
||||||
|
/* @var $attachmentGateway AttachmentGateway */
|
||||||
|
private $attachmentGateway;
|
||||||
|
|
||||||
|
/* @var $fileReader FileReader */
|
||||||
|
private $fileReader;
|
||||||
|
|
||||||
|
function __construct($attachmentGateway, $fileReader) {
|
||||||
|
$this->attachmentGateway = $attachmentGateway;
|
||||||
|
$this->fileReader = $fileReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAttachmentContentsForTicket($id, $heskSettings) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DataAccess\Files;
|
||||||
|
|
||||||
|
|
||||||
|
class FileReader {
|
||||||
|
/**
|
||||||
|
* @param $name string - The file name (including extension)
|
||||||
|
* @param $folder - The folder name (relative to the ROOT of the helpdesk)
|
||||||
|
* @param $contents string - The contents of the file to write
|
||||||
|
* @return int The file size, in bytes
|
||||||
|
* @throws \Exception When the file fails to save
|
||||||
|
*/
|
||||||
|
function readFromFile($name, $folder, $contents) {
|
||||||
|
// __DIR__ === '/{ROOT}/api/DataAccess/Files
|
||||||
|
$location = __DIR__ . "/../../../{$folder}/{$name}";
|
||||||
|
$fileContents = file_get_contents($location);
|
||||||
|
|
||||||
|
if ($fileContents === false) {
|
||||||
|
throw new \Exception("Failed to read the file!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fileContents;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace BusinessLogic\Attachments;
|
||||||
|
|
||||||
|
|
||||||
|
use DataAccess\Attachments\AttachmentGateway;
|
||||||
|
use DataAccess\Files\FileReader;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class AttachmentRetrieverTest extends TestCase {
|
||||||
|
/* @var $attachmentGateway \PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $attachmentGateway;
|
||||||
|
|
||||||
|
/* @var $fileReader \PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $fileReader;
|
||||||
|
|
||||||
|
/* @var $attachmentRetriever AttachmentRetriever */
|
||||||
|
private $attachmentRetriever;
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
$this->attachmentGateway = $this->createMock(AttachmentGateway::class);
|
||||||
|
$this->fileReader = $this->createMock(FileReader::class);
|
||||||
|
|
||||||
|
$this->attachmentRetriever = new AttachmentRetriever($this->attachmentGateway, $this->fileReader);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItGetsTheAttachmentFromTheFilesystem() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue