Refactor Tile constructor to accept parameters

master
Peter Babič 8 years ago
parent 5c57eec6a5
commit 42aad05241
Signed by: peter.babic
GPG Key ID: 4BB075BC1884BA40
  1. 113
      .idea/workspace.xml
  2. 4
      index.php
  3. 26
      src/Coffee/Spot.php
  4. 6
      tests/SpotTest.php

@ -4,11 +4,8 @@
<list default="true" id="65f95bb6-3a86-4ed6-841e-441936291ad4" name="Default" comment="Implement Tile.getNeighbors">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/index.php" afterPath="$PROJECT_DIR$/index.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Map.php" afterPath="$PROJECT_DIR$/src/Coffee/Map.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Tile.php" afterPath="$PROJECT_DIR$/src/Coffee/Tile.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/MapTest.php" afterPath="$PROJECT_DIR$/tests/MapTest.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Spot.php" afterPath="$PROJECT_DIR$/src/Coffee/Spot.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/SpotTest.php" afterPath="$PROJECT_DIR$/tests/SpotTest.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/TileTest.php" afterPath="$PROJECT_DIR$/tests/TileTest.php" />
</list>
<ignored path="coffeetable.iws" />
<ignored path=".idea/workspace.xml" />
@ -34,11 +31,11 @@
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="index.php" pinned="false" current-in-tab="true">
<file leaf-file-name="index.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/index.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.21900827">
<caret line="18" column="41" selection-start-line="18" selection-start-column="41" selection-end-line="18" selection-end-column="41" />
<state vertical-scroll-proportion="-14.666667">
<caret line="22" column="38" selection-start-line="22" selection-start-column="38" selection-end-line="22" selection-end-column="38" />
<folding />
</state>
</provider>
@ -47,8 +44,8 @@
<file leaf-file-name="Table.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-21.666666">
<caret line="69" column="29" selection-start-line="69" selection-start-column="29" selection-end-line="69" selection-end-column="29" />
<state vertical-scroll-proportion="-18.0">
<caret line="32" column="9" selection-start-line="32" selection-start-column="9" selection-end-line="32" selection-end-column="9" />
<folding />
</state>
</provider>
@ -104,11 +101,11 @@
</provider>
</entry>
</file>
<file leaf-file-name="Spot.php" pinned="false" current-in-tab="false">
<file leaf-file-name="Spot.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Coffee/Spot.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-8.666667">
<caret line="18" column="18" selection-start-line="18" selection-start-column="18" selection-end-line="18" selection-end-column="18" />
<state vertical-scroll-proportion="0.48987854">
<caret line="56" column="0" selection-start-line="56" selection-start-column="0" selection-end-line="56" selection-end-column="0" />
<folding />
</state>
</provider>
@ -117,8 +114,8 @@
<file leaf-file-name="SpotTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/SpotTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-5.3333335">
<caret line="8" column="0" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" />
<state vertical-scroll-proportion="-11.333333">
<caret line="17" column="0" selection-start-line="17" selection-start-column="0" selection-end-line="17" selection-end-column="0" />
<folding />
</state>
</provider>
@ -154,16 +151,16 @@
<option value="$PROJECT_DIR$/tests/Table.php" />
<option value="$PROJECT_DIR$/composer.json" />
<option value="$PROJECT_DIR$/.gitignore" />
<option value="$PROJECT_DIR$/src/Coffee/Spot.php" />
<option value="/usr/share/nginx/html/coffeetable/tests/TableTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Table.php" />
<option value="$PROJECT_DIR$/tests/TableTest.php" />
<option value="$PROJECT_DIR$/tests/SpotTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Map.php" />
<option value="$PROJECT_DIR$/tests/MapTest.php" />
<option value="$PROJECT_DIR$/tests/TileTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Tile.php" />
<option value="$PROJECT_DIR$/src/Coffee/Spot.php" />
<option value="$PROJECT_DIR$/index.php" />
<option value="$PROJECT_DIR$/tests/SpotTest.php" />
</list>
</option>
</component>
@ -539,38 +536,44 @@
<option name="project" value="LOCAL" />
<updated>1458154532845</updated>
</task>
<option name="localTasksCounter" value="7" />
<task id="LOCAL-00007" summary="Implement Tile.getNeighbors">
<created>1458201829369</created>
<option name="number" value="00007" />
<option name="project" value="LOCAL" />
<updated>1458201829369</updated>
</task>
<option name="localTasksCounter" value="8" />
<servers />
</component>
<component name="TestHistory">
<history-entry file="Tests - 2016.03.16 at 23h 43m 40s.xml">
<history-entry file="Tests - 2016.03.16 at 23h 56m 31s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.16 at 23h 45m 20s.xml">
<history-entry file="Tests - 2016.03.17 at 08h 21m 08s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.16 at 23h 55m 06s.xml">
<history-entry file="Tests - 2016.03.17 at 08h 57m 00s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.16 at 23h 55m 15s.xml">
<history-entry file="Tests - 2016.03.17 at 08h 59m 18s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.16 at 23h 55m 19s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 00m 05s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.16 at 23h 56m 31s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 11m 39s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 08h 21m 08s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 11m 56s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 08h 57m 00s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 12m 12s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 08h 59m 18s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 12m 39s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 09h 00m 05s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 12m 51s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
</component>
@ -579,10 +582,10 @@
<editor active="true" />
<layout>
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32917705" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32917705" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32917705" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.31670824" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.31670824" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.19375" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
@ -978,22 +981,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/SpotTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-5.3333335">
<caret line="8" column="0" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Spot.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-8.666667">
<caret line="18" column="18" selection-start-line="18" selection-start-column="18" selection-end-line="18" selection-end-column="18" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/TableTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-0.6666667">
@ -1002,14 +989,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-21.666666">
<caret line="69" column="29" selection-start-line="69" selection-start-column="29" selection-end-line="69" selection-end-column="29" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/MapTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-5.703704">
@ -1042,10 +1021,34 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-18.0">
<caret line="32" column="9" selection-start-line="32" selection-start-column="9" selection-end-line="32" selection-end-column="9" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/index.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.21900827">
<caret line="18" column="41" selection-start-line="18" selection-start-column="41" selection-end-line="18" selection-end-column="41" />
<state vertical-scroll-proportion="-14.666667">
<caret line="22" column="38" selection-start-line="22" selection-start-column="38" selection-end-line="22" selection-end-column="38" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/SpotTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-11.333333">
<caret line="17" column="0" selection-start-line="17" selection-start-column="0" selection-end-line="17" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Spot.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.48987854">
<caret line="56" column="0" selection-start-line="56" selection-start-column="0" selection-end-line="56" selection-end-column="0" />
<folding />
</state>
</provider>

@ -18,8 +18,8 @@ try {
foreach ($mapRow as $mapColumnIndex => $containsCoffee) {
if ($containsCoffee == true) {
$tile = new Tile($mapColumnIndex, $mapRowIndex);
$spot = new Spot();
$spot->addTile($tile);
$spot = new Spot($tile);
// $spot->addTile($tile);
$table->addSpot($spot);
}

@ -8,6 +8,11 @@
namespace Coffee;
/**
* Class Spot
*
* @package Coffee
*/
/**
* Class Spot
*
@ -20,6 +25,27 @@ class Spot {
*/
private $tiles = [];
/**
* Spot constructor.
*
* @param Tile|Tile[] $tiles
*/
public function __construct($tiles = null) {
if ($tiles instanceof Tile) {
$this->addTile($tiles);
}
if (is_array($tiles)) {
foreach ($tiles as $tile) {
$this->addTile($tile);
}
}
}
/**
* @param Tile $tile
* @return bool
*/
public function addTile(Tile $tile) {
if (is_null($tile)) {
return false;

@ -9,9 +9,9 @@ class SpotTest extends \PHPUnit_Framework_TestCase {
public function testGetTiles() {
$tile = new Tile(2, 1);
$spot = new Spot();
$spot->addTile($tile);
$spot = new Spot([$tile, $tile]);
// $spot->addTile($tile);
$this->assertEquals([$tile], $spot->getTiles());
$this->assertEquals([$tile, $tile], $spot->getTiles());
}
}

Loading…
Cancel
Save