Skip to content

Commit

Permalink
Change transcode to convert
Browse files Browse the repository at this point in the history
  • Loading branch information
rkoopmans committed Sep 20, 2022
1 parent a0644b5 commit b527106
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/Tinify/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function store($options) {
return new Result($response->headers, $response->body);
}

public function transcode($types) {
$commands = array_merge($this->commands, array("type" => $types));
public function convert($options) {
$commands = array_merge($this->commands, array("convert" => $options));
return new self($this->url, $commands);
}

Expand Down
14 changes: 7 additions & 7 deletions test/TinifySourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,34 +226,34 @@ public function testResizeShouldReturnSourceWithData() {
$this->assertSame("{\"resize\":{\"width\":400}}", CurlMock::last(CURLOPT_POSTFIELDS));
}

public function testTranscodeShouldReturnSource() {
public function testConvertShouldReturnSource() {
Tinify\setKey("valid");

CurlMock::register("https://api.tinify.com/shrink", array(
"status" => 201, "headers" => array("Location" => "https://api.tinify.com/some/location")
));

CurlMock::register("https://api.tinify.com/some/location", array(
"status" => 200, "body" => "transcoded file"
"status" => 200, "body" => "Convertd file"
));

$this->assertInstanceOf("Tinify\Source", Tinify\Source::fromBuffer("png file")->transcode("image/webp"));
$this->assertInstanceOf("Tinify\Source", Tinify\Source::fromBuffer("png file")->Convert(array("type" =>"image/webp")));
$this->assertSame("png file", CurlMock::last(CURLOPT_POSTFIELDS));
}

public function testTranscodeShouldReturnSourceWithData() {
public function testConvertShouldReturnSourceWithData() {
Tinify\setKey("valid");

CurlMock::register("https://api.tinify.com/shrink", array(
"status" => 201, "headers" => array("Location" => "https://api.tinify.com/some/location")
));

CurlMock::register("https://api.tinify.com/some/location", array(
"status" => 200, "body" => "transcoded file"
"status" => 200, "body" => "Convertd file"
));

$this->assertSame("transcoded file", Tinify\Source::fromBuffer("png file")->transcode("image/webp")->toBuffer());
$this->assertSame("{\"type\":\"image\/webp\"}", CurlMock::last(CURLOPT_POSTFIELDS));
$this->assertSame("Convertd file", Tinify\Source::fromBuffer("png file")->convert(array("type" => "image/webp"))->toBuffer());
$this->assertSame("{\"convert\":{\"type\":\"image\/webp\"}}", CurlMock::last(CURLOPT_POSTFIELDS));
}

public function testTransformShouldReturnSource() {
Expand Down
4 changes: 2 additions & 2 deletions test/integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public function testShouldPreserveMetadata() {
$this->assertStringContainsString("Copyright Voormedia", $contents);
}

public function testShouldTranscode() {
public function testShouldConvert() {
$path = tempnam(sys_get_temp_dir(), "tinify-php");
self::$optimized->transcode(["image/webp"])->toFile($path);
self::$optimized->convert(array("type" => ["image/webp"]))->toFile($path);

$size = filesize($path);
$contents = fread(fopen($path, "rb"), $size);
Expand Down

0 comments on commit b527106

Please sign in to comment.