Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ytake committed Aug 28, 2014
1 parent 4798f0a commit 1d484d4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app/App/Commands/AddRecipeCommand.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace App\Commands;

use App\Repositories\RecipeRepositoryInterface;
use Illuminate\Console\Command;
use App\Repositories\RecipeRepositoryInterface;
use App\Repositories\CategoryRepositoryInterface;

/**
Expand Down Expand Up @@ -73,7 +73,6 @@ protected function addRecipes(array $dir, $files, \stdClass $category)
{

foreach ($dir as $value) {

if ($value != "." && $value != "..") {
$file = \File::get("{$files}/{$value}");
$problem = $this->getParseContents('problem', $file);
Expand Down
10 changes: 8 additions & 2 deletions app/App/Presenter/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ public function getFeeder()
*/
public function render()
{
$feed = $this->feed->export($this->format);
return \Response::make($feed, 200, $this->header[$this->format]);
try {
$feed = $this->feed->export($this->format);
return \Response::make($feed, 200, $this->header[$this->format]);
} catch(\Zend\Feed\Writer\Exception\InvalidArgumentException $w) {

return \Response::make([], 404);
}

}
}
23 changes: 21 additions & 2 deletions app/tests/Commands/AddRecipeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
use Mockery as m;
use App\Tests\TestCase;
use App\Commands\AddRecipeCommand;
use Symfony\Component\Console\Output\NullOutput;
use App\Tests\StubRepositories\RecipeRepository;
use App\Tests\StubRepositories\CategoryRepository;

class AddRecipeCommandTest extends TestCase
{
/** @var AddRecipeCommand */
protected $command;
/** @var CategoryRepository */
protected $category;

public function tearDown()
{
Expand All @@ -20,7 +23,8 @@ public function tearDown()
public function setUp()
{
parent::setUp();
$this->command = new AddRecipeCommand(new CategoryRepository, new RecipeRepository);
$this->category = new CategoryRepository;
$this->command = new AddRecipeCommand($this->category, new RecipeRepository);

}

Expand Down Expand Up @@ -61,7 +65,6 @@ public function testParseHeader()

public function testConvertGfm()
{
$filePath = \File::get(__DIR__ . "/../docs/test.md");
$reflectionMethod = $this->getProtectMethod($this->command, 'convertGfm');
$text = '{php}
function()
Expand All @@ -86,4 +89,20 @@ function()
$result = $reflectionMethod->invokeArgs($this->command, ["string" => $text]);
$this->assertSame($convert, $result);
}

public function testAddRecipes()
{
$reflectionProperty = $this->getProtectProperty($this->command, 'output');
$reflectionProperty->setValue($this->command, new NullOutput());
$dir = scandir(app_path() . "/tests/docs");
$reflectionMethod = $this->getProtectMethod($this->command, 'addRecipes');
$reflectionMethod->invokeArgs($this->command, [$dir, app_path() . "/tests/docs", $this->category->getCategory(1)]);
$this->assertInstanceOf("Symfony\Component\Console\Output\NullOutput", $this->command->getOutput());
}

public function testAddRecipeCommand()
{
$this->command->run(new \Symfony\Component\Console\Input\ArrayInput([]), new \Symfony\Component\Console\Output\NullOutput);
$this->assertInstanceOf("Symfony\Component\Console\Output\NullOutput", $this->command->getOutput());
}
}
5 changes: 5 additions & 0 deletions app/tests/Controllers/FeedControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public function testIndexRss()
$this->assertSame('application/rss+xml; charset=utf-8', $request->headers->get('content-type'));
}

public function testNotAllowFormat()
{
$this->client->request('GET', '/feed/rdf');
$this->assertTrue($this->client->getResponse()->isNotFound());
}

public function testSiteMap()
{
Expand Down
8 changes: 7 additions & 1 deletion app/tests/StubRepositories/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ public function getCategoryFromSection($sectionId)
*/
public function getCategory($id)
{
// TODO: Implement getCategory() method.
$result = false;
foreach($this->categories as $category) {
if($category['category_id'] == $id) {
$result = (object) $category;
}
}
return $result;
}

/**
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
strict="true"
verbose="true"
>
<testsuites>
Expand Down

0 comments on commit 1d484d4

Please sign in to comment.