Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing route for new fields #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/PlaylistFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ class PlaylistFormatter
* @var Registry
*/
private $registry;
private $testing;

/**
* PlaylistFormatter constructor.
*
* @param Registry $registry
* @param bool $testing Whether or not to include fields currently in testing.
*/
public function __construct(Registry $registry)
public function __construct(Registry $registry, $testing = false)
{
$this->registry = $registry;
$this->testing = $testing;
}

/**
Expand All @@ -39,9 +42,13 @@ public function __toString()
$entry['coreversion'],
$entry['gamename'],
$entry['gamecrc'],
//$entry['haspassword'] ? '1' : '0',
$entry['created'],
);

// If we are testing any new fields, add them here.
if ($this->testing) {
array_push($properties, $entry['haspassword'] ? '1' : '0');
}
array_push($output, implode($properties, "\n"));
}
return implode($output, "\n");
Expand Down
2 changes: 1 addition & 1 deletion test/PlaylistFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function testToString()
$entry['coreversion'],
$entry['gamename'],
$entry['gamecrc'],
//$entry['haspassword'],
$entry['created']
//$entry['haspassword']
);
$output = implode($properties, "\n");
$playlist = new PlaylistFormatter($this->registry);
Expand Down
25 changes: 25 additions & 0 deletions testing/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use RobLoach\LibretroNetplayRegistry\PlaylistFormatter;
use RobLoach\LibretroNetplayRegistry\Registry;
use RobLoach\LibretroNetplayRegistry\InputParser;

// Set the content type.
header('Content-Type: text/plain');

// Load the classes.
require __DIR__ . '/../src/autoload.php';

// Load the registry.
$registry = new Registry('../.registry');

// Check if we are adding a new entry.
$input = new InputParser();
$newEntry = $input->getEntry();
if ($newEntry) {
$registry->insert($newEntry);
}

// Output the new playlist.
$playlist = new PlaylistFormatter($registry, true);
echo $playlist;