Skip to content

Commit

Permalink
Update PHP code to rely on latest JSON data file locations. (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz authored Aug 28, 2024
1 parent e45b33b commit 54cd44d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions inc/ThirdParties/GoogleAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace GoogleChromeLabs\ThirdPartyCapital\ThirdParties;

use GoogleChromeLabs\ThirdPartyCapital\Util\ThirdPartiesDir;
use GoogleChromeLabs\ThirdPartyCapital\Util\JsonDir;

/**
* Class representing the Google Analytics integration.
Expand All @@ -24,6 +24,6 @@ class GoogleAnalytics extends ThirdPartyBase
*/
protected function getJsonFilePath(): string
{
return ThirdPartiesDir::getFilePath('google-analytics/data.json');
return JsonDir::getFilePath('google-analytics.json');
}
}
4 changes: 2 additions & 2 deletions inc/ThirdParties/GoogleMapsEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace GoogleChromeLabs\ThirdPartyCapital\ThirdParties;

use GoogleChromeLabs\ThirdPartyCapital\Util\ThirdPartiesDir;
use GoogleChromeLabs\ThirdPartyCapital\Util\JsonDir;

/**
* Class representing the Google Maps Embed integration.
Expand All @@ -24,6 +24,6 @@ class GoogleMapsEmbed extends ThirdPartyBase
*/
protected function getJsonFilePath(): string
{
return ThirdPartiesDir::getFilePath('google-maps-embed/data.json');
return JsonDir::getFilePath('google-maps-embed.json');
}
}
4 changes: 2 additions & 2 deletions inc/ThirdParties/YouTubeEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace GoogleChromeLabs\ThirdPartyCapital\ThirdParties;

use GoogleChromeLabs\ThirdPartyCapital\Util\ThirdPartiesDir;
use GoogleChromeLabs\ThirdPartyCapital\Util\JsonDir;

/**
* Class representing the YouTube Embed integration.
Expand All @@ -24,6 +24,6 @@ class YouTubeEmbed extends ThirdPartyBase
*/
protected function getJsonFilePath(): string
{
return ThirdPartiesDir::getFilePath('youtube-embed/data.json');
return JsonDir::getFilePath('youtube-embed.json');
}
}
12 changes: 6 additions & 6 deletions inc/Util/ThirdPartiesDir.php → inc/Util/JsonDir.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Class GoogleChromeLabs\ThirdPartyCapital\Util\ThirdPartiesDir
* Class GoogleChromeLabs\ThirdPartyCapital\Util\JsonDir
*
* @package GoogleChromeLabs/ThirdPartyCapital
* @copyright 2024 Google LLC
Expand All @@ -10,20 +10,20 @@
namespace GoogleChromeLabs\ThirdPartyCapital\Util;

/**
* Static class providing the path to the 'third-parties' directory containing JSON files.
* Static class providing the path to the directory containing JSON files.
*/
class ThirdPartiesDir
class JsonDir
{

/**
* Gets the absolute path to a file within the 'third-parties' directory.
* Gets the absolute path to a file within the JSON directory.
*
* @param string $relativePath Relative path to the file within the 'third-parties' directory.
* @param string $relativePath Relative path to the file within the JSON directory.
* @return string Absolute path to the file.
*/
public static function getFilePath(string $relativePath): string
{
$dir = dirname(__DIR__, 2) . '/src/third-parties/';
$dir = dirname(__DIR__, 2) . '/data/';

return $dir . ltrim($relativePath, '/');
}
Expand Down
29 changes: 29 additions & 0 deletions tests/phpunit/tests/Util/JsonDirTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Tests for GoogleChromeLabs\ThirdPartyCapital\Util\JsonDir
*
* @package GoogleChromeLabs/ThirdPartyCapital
* @copyright 2024 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
*/

namespace GoogleChromeLabs\ThirdPartyCapital\Tests;

use GoogleChromeLabs\ThirdPartyCapital\TestUtils\TestCase;
use GoogleChromeLabs\ThirdPartyCapital\Util\JsonDir;

class JsonDirTest extends TestCase
{

public function testGetFilePath()
{
$absPath = JsonDir::getFilePath('google-analytics.json');
$this->assertStringEndsWith('/data/google-analytics.json', $absPath);
}

public function testGetFilePathWithLeadingSlash()
{
$absPath = JsonDir::getFilePath('/google-analytics.json');
$this->assertStringEndsWith('/data/google-analytics.json', $absPath);
}
}
29 changes: 0 additions & 29 deletions tests/phpunit/tests/Util/ThirdPartiesDirTest.php

This file was deleted.

0 comments on commit 54cd44d

Please sign in to comment.