mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-20 13:23:47 -07:00
Version 3 release. Major re-write
This commit is contained in:
parent
127ad7e14a
commit
f9b49002c7
1507 changed files with 6592 additions and 94204 deletions
80
tests/FileTest.php
Normal file
80
tests/FileTest.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use SpacesAPI\Exceptions\FileDoesntExistException;
|
||||
use SpacesAPI\Exceptions\SpaceDoesntExistException;
|
||||
use SpacesAPI\Spaces;
|
||||
|
||||
class FileTest extends TestCase
|
||||
{
|
||||
private static $space;
|
||||
private static $file;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$dotenv = Dotenv::createImmutable(__DIR__ . "/..");
|
||||
$dotenv->load();
|
||||
$dotenv->required(['SPACES_KEY', 'SPACES_SECRET']);
|
||||
|
||||
$spaces = new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']);
|
||||
|
||||
try {
|
||||
$spaces->space('spaces-api-test')->destroySpace();
|
||||
} catch (SpaceDoesntExistException $e) {
|
||||
}
|
||||
|
||||
self::$space = $spaces->create('spaces-api-test');
|
||||
self::$file = self::$space->uploadText('Lorem ipsum', 'lorem-ipsum.txt');
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroySpace();
|
||||
}
|
||||
|
||||
public function testCanUpdatePrivacy()
|
||||
{
|
||||
$this->assertFalse(self::$file->isPublic());
|
||||
|
||||
self::$file->makePublic();
|
||||
$this->assertTrue(self::$file->isPublic());
|
||||
|
||||
self::$file->makePrivate();
|
||||
$this->assertFalse(self::$file->isPublic());
|
||||
}
|
||||
|
||||
public function testCanGetContents()
|
||||
{
|
||||
$this->assertEquals("Lorem ipsum", self::$file->getContents());
|
||||
}
|
||||
|
||||
public function testCanDownloadFile()
|
||||
{
|
||||
$filename = sys_get_temp_dir() . "/lorem.txt";
|
||||
self::$file->download($filename);
|
||||
|
||||
$this->assertEquals("Lorem ipsum", file_get_contents($filename));
|
||||
}
|
||||
|
||||
public function testCanCopyFile()
|
||||
{
|
||||
$this->expectNotToPerformAssertions();
|
||||
self::$file->copy('lorem-ipsum-2.txt');
|
||||
self::$space->file('lorem-ipsum-2.txt');
|
||||
}
|
||||
|
||||
public function testCanGetURL()
|
||||
{
|
||||
$this->assertStringContainsString('lorem-ipsum.txt', self::$file->getURL());
|
||||
$this->assertStringContainsString('lorem-ipsum.txt', self::$file->getSignedURL());
|
||||
}
|
||||
|
||||
public function testCanDeleteFile()
|
||||
{
|
||||
self::$file->delete();
|
||||
|
||||
$this->expectException(FileDoesntExistException::class);
|
||||
self::$space->file('lorem-ipsum.txt');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue