diff --git a/build.xml b/build.xml index 7c41eb88..f223f795 100755 --- a/build.xml +++ b/build.xml @@ -1,6 +1,6 @@ - + @@ -123,7 +123,7 @@ - + @@ -139,7 +139,7 @@ - + @@ -151,10 +151,11 @@ - + + @@ -187,7 +188,8 @@ Finished. - + + diff --git a/build/phpcs.xml b/build/phpcs.xml new file mode 100644 index 00000000..35937a1c --- /dev/null +++ b/build/phpcs.xml @@ -0,0 +1,227 @@ + + + Itero code standart + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/php/unit/Config/ConfigTest.php b/tests/php/unit/Config/ConfigTest.php index e104b39c..2d7380d0 100755 --- a/tests/php/unit/Config/ConfigTest.php +++ b/tests/php/unit/Config/ConfigTest.php @@ -2,45 +2,44 @@ namespace Notes\Config; class ConfigTest extends \PHPUnit_Framework_TestCase -{ - +{ public function testCanAcceptConfigurationForIntegrationEnviornment() - { + { $config=new Config("config_integration.json"); $result=$config->get(); $this->assertEquals("localhost", $result['dbHost']); $this->assertEquals("notes-@GIT_BRANCH", $result['dbName']); $this->assertEquals("developer", $result['dbUser']); $this->assertEquals("test123", $result['dbPassword']); - } + } public function testCanAcceptConfigurationForDevEnviornment() - { + { $config=new Config("config_dev.json"); $result=$config->get(); $this->assertEquals("localhost", $result['dbHost']); $this->assertEquals("notes-@GIT_BRANCH", $result['dbName']); $this->assertEquals("developer", $result['dbUser']); $this->assertEquals("test123", $result['dbPassword']); - } + } public function testCanAcceptConfigurationForBetaEnviornment() - { + { $config=new Config("config_beta.json"); $result=$config->get(); $this->assertEquals("localhost", $result['dbHost']); $this->assertEquals("notes-@GIT_BRANCH", $result['dbName']); $this->assertEquals("developer", $result['dbUser']); $this->assertEquals("test123", $result['dbPassword']); - } + } public function testCanAcceptConfigurationForMasterEnviornment() - { + { $config=new Config("config_master.json"); $result=$config->get(); $this->assertEquals("localhost", $result['dbHost']); $this->assertEquals("notes-@GIT_BRANCH", $result['dbName']); $this->assertEquals("developer", $result['dbUser']); $this->assertEquals("test123", $result['dbPassword']); - } + } } diff --git a/tests/php/unit/Domain/NoteTest.php b/tests/php/unit/Domain/NoteTest.php index 4e0506b3..86afff30 100755 --- a/tests/php/unit/Domain/NoteTest.php +++ b/tests/php/unit/Domain/NoteTest.php @@ -402,11 +402,8 @@ public function testCanUpdate() $this->assertEquals('Web', $noteModel->getTitle()); $this->assertEquals('PHP is a powerful tool for making dynamic Web pages.', $noteModel->getBody()); - $noteTagCollection = $noteModel->getNoteTags(); while ($noteTagCollection->hasNext()) { - - $this->assertEquals(1, $noteTagCollection->getRow(0)->getId()); $this->assertEquals(1, $noteTagCollection->getRow(0)->getNoteId()); $this->assertEquals(1, $noteTagCollection->getRow(0)->getUserTagId()); diff --git a/tests/php/unit/Domain/SessionTest.php b/tests/php/unit/Domain/SessionTest.php index 106efa18..117b8b34 100755 --- a/tests/php/unit/Domain/SessionTest.php +++ b/tests/php/unit/Domain/SessionTest.php @@ -196,12 +196,12 @@ public function it_should_throw_exception_with_invalid_authToken_userId() */ public function it_should_throw_exception_with_invalid_email_password() { - $userInput = array( + $userInput = array( 'email' => 'abcd@gmail.com', 'password' => 'Joy%hj5487' - ); - $userModel = new UserModel(); + ); + $userModel = new UserModel(); $userModel->setEmail($userInput['email']); $userModel->setPassword($userInput['password']); @@ -209,7 +209,7 @@ public function it_should_throw_exception_with_invalid_email_password() 'authToken' => 'pqr', 'createdOn' => '2015-01-29 20:59:59', 'expiredOn' => '2015-01-29 20:59:59' - ); + ); $sessionModel = new sessionModel(); $sessionModel->setAuthToken($input['authToken']); $sessionModel->setCreatedOn($input['createdOn']); diff --git a/tests/php/unit/Domain/UserTagTest.php b/tests/php/unit/Domain/UserTagTest.php index 019f50ee..2ec160c1 100755 --- a/tests/php/unit/Domain/UserTagTest.php +++ b/tests/php/unit/Domain/UserTagTest.php @@ -28,11 +28,9 @@ public function getConnection() $this->connection = new \PDO($hostString, $configData['dbUser'], $configData['dbPassword']); $this->connection->exec("set foreign_key_checks=0"); return $this->createDefaultDBConnection($this->connection, $dbName); - } - catch (\PDOException $e) { + } catch (\PDOException $e) { echo "Connection failed: " . $e->getMessage(); } - } public function getDataSet() @@ -53,6 +51,34 @@ public function testCanCreateTag() $userTagDomain = new UserTag(); $userTagModel = $userTagDomain->create($userTagModel); + + $expectedDataSet = $this->createXmlDataSet(dirname(__FILE__) . '/_files/userTagDomain_after_create.xml'); + $actualDataSet = $this->getConnection()->createDataSet(array( + 'UserTags' + )); + + $this->assertEquals(4, $userTagModel->getId()); + $this->assertEquals(3, $userTagModel->getUserId()); + $this->assertEquals('Create', $userTagModel->getTag()); + $this->assertEquals(0, $userTagModel->getIsDeleted()); + $this->assertDataSetsEqual($expectedDataSet, $actualDataSet); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Input should not be null + */ + public function testThrowsExceptionWhenUserIdIsNull() + { + $input = array( + 'tag' => 'Create' + ); + + $userTagModel = new UserTagModel(); + $userTagModel->setTag($input['tag']); + + $userTagDomain = new UserTag(); + $userTagModel = $userTagDomain->create($userTagModel); $expectedDataSet = $this->createXmlDataSet(dirname(__FILE__) . '/_files/userTagDomain_after_create.xml'); @@ -66,34 +92,7 @@ public function testCanCreateTag() $this->assertEquals(0, $userTagModel->getIsDeleted()); $this->assertDataSetsEqual($expectedDataSet, $actualDataSet); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Input should not be null - */ - public function testThrowsExceptionWhenUserIdIsNull() - { - $input = array( - 'tag' => 'Create' - ); - - $userTagModel = new UserTagModel(); - $userTagModel->setTag($input['tag']); - - $userTagDomain = new UserTag(); - $userTagModel = $userTagDomain->create($userTagModel); - - - $expectedDataSet = $this->createXmlDataSet(dirname(__FILE__) . '/_files/userTagDomain_after_create.xml'); - $actualDataSet = $this->getConnection()->createDataSet(array( - 'UserTags' - )); - - $this->assertEquals(4, $userTagModel->getId()); - $this->assertEquals(3, $userTagModel->getUserId()); - $this->assertEquals('Create', $userTagModel->getTag()); - $this->assertEquals(0, $userTagModel->getIsDeleted()); - $this->assertDataSetsEqual($expectedDataSet, $actualDataSet); - } + public function testCanReadTagByUserId() { $input = array( @@ -112,13 +111,13 @@ public function testCanReadTagByUserId() 'UserTags' )); - while($userTagCollection->hasNext()) { - $this->assertEquals(3, $userTagCollection->getRow(0)->getId()); - $this->assertEquals(2, $userTagCollection->getRow(0)->getUserId()); - $this->assertEquals('People', $userTagCollection->getRow(0)->getTag()); - $this->assertEquals(0, $userTagCollection->getRow(0)->getIsDeleted()); - $userTagCollection->next(); - } + while ($userTagCollection->hasNext()) { + $this->assertEquals(3, $userTagCollection->getRow(0)->getId()); + $this->assertEquals(2, $userTagCollection->getRow(0)->getUserId()); + $this->assertEquals('People', $userTagCollection->getRow(0)->getTag()); + $this->assertEquals(0, $userTagCollection->getRow(0)->getIsDeleted()); + $userTagCollection->next(); + } $this->assertDataSetsEqual($expectedDataSet, $actualDataSet); } diff --git a/tests/php/unit/Mapper/NoteTagTest.php b/tests/php/unit/Mapper/NoteTagTest.php index ed198804..6fbb45ed 100755 --- a/tests/php/unit/Mapper/NoteTagTest.php +++ b/tests/php/unit/Mapper/NoteTagTest.php @@ -55,13 +55,13 @@ public function testCanReadRecordByNoteId() $this->assertDataSetsEqual($expectedDataSet, $actualDataSet); - while($noteTagCollection->hasNext()) { - $this->assertEquals(1, $noteTagCollection->getRow(0)->getId()); - $this->assertEquals(4, $noteTagCollection->getRow(0)->getNoteId()); - $this->assertEquals(3, $noteTagCollection->getRow(0)->getUserTagId()); - $this->assertEquals(0, $noteTagCollection->getRow(0)->getIsDeleted()); - $noteTagCollection->next(); - } + while ($noteTagCollection->hasNext()) { + $this->assertEquals(1, $noteTagCollection->getRow(0)->getId()); + $this->assertEquals(4, $noteTagCollection->getRow(0)->getNoteId()); + $this->assertEquals(3, $noteTagCollection->getRow(0)->getUserTagId()); + $this->assertEquals(0, $noteTagCollection->getRow(0)->getIsDeleted()); + $noteTagCollection->next(); + } } /** * @expectedException Notes\Exception\ModelNotFoundException diff --git a/tests/php/unit/Mapper/UserTagTest.php b/tests/php/unit/Mapper/UserTagTest.php index 91862a8e..f50dca23 100755 --- a/tests/php/unit/Mapper/UserTagTest.php +++ b/tests/php/unit/Mapper/UserTagTest.php @@ -89,13 +89,13 @@ public function testCanReadRecordByUserId() $this->assertDataSetsEqual($expectedDataSet, $actualDataSet); - while($userTagCollection->hasNext()) { - $this->assertEquals(1, $userTagCollection->getRow(0)->getId()); - $this->assertEquals(1, $userTagCollection->getRow(0)->getUserId()); - $this->assertEquals('Import package', $userTagCollection->getRow(0)->getTag()); - $this->assertEquals(0, $userTagCollection->getRow(0)->getIsDeleted()); - $userTagCollection->next(); - } + while ($userTagCollection->hasNext()) { + $this->assertEquals(1, $userTagCollection->getRow(0)->getId()); + $this->assertEquals(1, $userTagCollection->getRow(0)->getUserId()); + $this->assertEquals('Import package', $userTagCollection->getRow(0)->getTag()); + $this->assertEquals(0, $userTagCollection->getRow(0)->getIsDeleted()); + $userTagCollection->next(); + } } public function testCanInsertRecord() diff --git a/tests/php/unit/Model/NoteTest.php b/tests/php/unit/Model/NoteTest.php index c1ceaf94..a629ae80 100755 --- a/tests/php/unit/Model/NoteTest.php +++ b/tests/php/unit/Model/NoteTest.php @@ -1,12 +1,21 @@ -1, 'userId'=>1, 'title'=>'PHP', 'body'=>'Preprocessor Hypertext','createdOn' => '2015-02-16 08:56:44', 'lastUpdateOn' => '2015-02-16 08:56:44', 'isDeleted' => 0); - $note = new Note($params); - $this->assertInstanceOf('Notes\Model\Note', $note); - } -} +1, + 'userId'=>1, + 'title'=>'PHP', + 'body'=>'Preprocessor Hypertext', + 'createdOn' => '2015-02-16 08:56:44', + 'lastUpdateOn' => '2015-02-16 08:56:44', + 'isDeleted' => 0 + ); + + $note = new Note($params); + $this->assertInstanceOf('Notes\Model\Note', $note); + } +} diff --git a/tests/php/unit/Model/UserTest.php b/tests/php/unit/Model/UserTest.php index 7e776dde..bbceb694 100755 --- a/tests/php/unit/Model/UserTest.php +++ b/tests/php/unit/Model/UserTest.php @@ -1,80 +1,78 @@ - 1, - 'firstName' => 'anusha', - 'lastName' => 'hiremath', - 'email' => 'anusha@gmail.com', - 'password' => 'sfhsk1223', - 'createdOn' => '2014-10-31 20:59:59' - ); - $userModel = new UserModel(); - $userModel->setId($userInput['id']); - $userModel->setFirstName($userInput['firstName']); - $userModel->setLastName($userInput['lastName']); - $userModel->setEmail($userInput['email']); - $userModel->setPassword($userInput['password']); - $userModel->setCreatedOn($userInput['createdOn']); - - $this->assertEquals(1, $userModel->getId()); - $this->assertEquals('anusha', $userModel->getFirstName()); - $this->assertEquals('hiremath', $userModel->getLastName()); - $this->assertEquals('anusha@gmail.com', $userModel->getEmail()); - $this->assertEquals('sfhsk1223', $userModel->getPassword()); - $this->assertEquals('2014-10-31 20:59:59', $userModel->getCreatedOn()); - - } - /** - *@test - * - **/ - - public function it_should_set_single_property() - { - - $userInput = array( - 'firstName' => 'anusha' - ); - $userModel = new UserModel(); - $userModel->setId($userInput['firstName']); - $this->assertEquals('anusha', $userModel->getId()); - - } - /** - *@test - * - **/ - public function it_should_convert_object_into_array() - { - $userInput=array( - 'id' => 1, - 'firstName' => 'Joy', - 'lastName' => 'Mock', - 'email' => 'joy@mok.com', - 'password' => 'Joy#@Mo124', - 'createdOn' => '2014-2-4 12:41:36'); - - $userModel=new UserModel(); - $userModel->setId($userInput['id']); - $userModel->setFirstName($userInput['firstName']); - $userModel->setLastName($userInput['lastName']); - $userModel->setEmail($userInput['email']); - $userModel->setPassword($userInput['password']); - $userModel->setCreatedOn($userInput['createdOn']); - - - $this->assertEquals($userInput,$userModel->toArray()); - } -} + 1, + 'firstName' => 'anusha', + 'lastName' => 'hiremath', + 'email' => 'anusha@gmail.com', + 'password' => 'sfhsk1223', + 'createdOn' => '2014-10-31 20:59:59' + ); + $userModel = new UserModel(); + $userModel->setId($userInput['id']); + $userModel->setFirstName($userInput['firstName']); + $userModel->setLastName($userInput['lastName']); + $userModel->setEmail($userInput['email']); + $userModel->setPassword($userInput['password']); + $userModel->setCreatedOn($userInput['createdOn']); + + $this->assertEquals(1, $userModel->getId()); + $this->assertEquals('anusha', $userModel->getFirstName()); + $this->assertEquals('hiremath', $userModel->getLastName()); + $this->assertEquals('anusha@gmail.com', $userModel->getEmail()); + $this->assertEquals('sfhsk1223', $userModel->getPassword()); + $this->assertEquals('2014-10-31 20:59:59', $userModel->getCreatedOn()); + + } + /** + *@test + * + **/ + + public function it_should_set_single_property() + { + + $userInput = array( + 'firstName' => 'anusha' + ); + $userModel = new UserModel(); + $userModel->setId($userInput['firstName']); + $this->assertEquals('anusha', $userModel->getId()); + + } + /** + *@test + * + **/ + public function it_should_convert_object_into_array() + { + $userInput=array( + 'id' => 1, + 'firstName' => 'Joy', + 'lastName' => 'Mock', + 'email' => 'joy@mok.com', + 'password' => 'Joy#@Mo124', + 'createdOn' => '2014-2-4 12:41:36'); + + $userModel=new UserModel(); + $userModel->setId($userInput['id']); + $userModel->setFirstName($userInput['firstName']); + $userModel->setLastName($userInput['lastName']); + $userModel->setEmail($userInput['email']); + $userModel->setPassword($userInput['password']); + $userModel->setCreatedOn($userInput['createdOn']); + + $this->assertEquals($userInput, $userModel->toArray()); + } +} diff --git a/tests/php/unit/Request/RequestTest.php b/tests/php/unit/Request/RequestTest.php index a329e758..6731af6d 100755 --- a/tests/php/unit/Request/RequestTest.php +++ b/tests/php/unit/Request/RequestTest.php @@ -46,7 +46,9 @@ public function it_should_set_headers_urlParams_and_cookies() 'Cache-Control' => 'no-cache', 'Origin' => 'chrome-extension://mkhojklkhkdaghjjfdnphfphiaiohkef', 'Client-Header' => 'Header Test', - 'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36', + 'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) + AppleWebKit/537.36 (KHTML, like Gecko) + Chrome/41.0.2272.89 Safari/537.36', 'Content-Type' => 'text/plain', 'charset'=>'UTF-8' , 'Accept-Encoding' => 'gzip, deflate' @@ -64,9 +66,9 @@ public function it_should_set_headers_urlParams_and_cookies() $request->setUrlParams($urlParams); $request->setCookies($cookies); - $this->assertEquals($headers,$request->getHeaders()); - $this->assertEquals($urlParams,$request->getUrlParams()); - $this->assertEquals($cookies,$request->getCookies()); + $this->assertEquals($headers, $request->getHeaders()); + $this->assertEquals($urlParams, $request->getUrlParams()); + $this->assertEquals($cookies, $request->getCookies()); } diff --git a/tests/php/unit/Routes/RoutesTest.php b/tests/php/unit/Routes/RoutesTest.php index 2b1cd304..1c982e02 100755 --- a/tests/php/unit/Routes/RoutesTest.php +++ b/tests/php/unit/Routes/RoutesTest.php @@ -23,8 +23,7 @@ public function homepage_should_be_loaded_with_url_parameter_home() { $client=new ClientRequest(); $parameters = array('home'); - - $client->get('/' ,$parameters); - $this->assertEquals(200, $client->response->status()); + $client->get('/', $parameters); + $this->assertEquals(200, $client->response->status()); } } diff --git a/tests/php/unit/Service/SessionTest.php b/tests/php/unit/Service/SessionTest.php index f68750c8..5ed9163c 100755 --- a/tests/php/unit/Service/SessionTest.php +++ b/tests/php/unit/Service/SessionTest.php @@ -80,8 +80,7 @@ public function it_should_read_session_by_userId_and_authToken() $sessionModel->setAuthToken($input['authToken']); $sessionService = new Session(); - - $this->assertEquals(true, $sessionService->isValid($sessionModel)); + $this->assertEquals(true, $sessionService->isValid($sessionModel)); } /** diff --git a/tests/php/unit/View/HomeTest.php b/tests/php/unit/View/HomeTest.php index 0b706784..6df3d278 100755 --- a/tests/php/unit/View/HomeTest.php +++ b/tests/php/unit/View/HomeTest.php @@ -16,8 +16,8 @@ public function setUp() * **/ public function Home_page_loaded() - { - $homeLayout = array( + { + $homeLayout = array( "h1"=> "Wel-come to Sticky-notes", "register"=> "New User:Register", "login"=> "Login" diff --git a/tests/php/unit/View/LoginTest.php b/tests/php/unit/View/LoginTest.php index 5ea595cc..4a76934c 100755 --- a/tests/php/unit/View/LoginTest.php +++ b/tests/php/unit/View/LoginTest.php @@ -14,19 +14,15 @@ public function setUp() *@test * **/ - public function Login_page_loaded() - { - $homeLayout = array('login' => 'Login'); - + public function login_page_loaded() + { + $homeLayout = array('login' => 'Login'); $contentTemplateName = 'login'; $output = $this->view->renderContent($contentTemplateName, $homeLayout); - - $dom = new \DOMDocument(); $dom->loadHTML($output); - $element = $dom->getElementsByTagName('h1'); $this->assertEquals("Login", $element->item(0)->nodeValue); diff --git a/tests/php/unit/View/NoteTest.php b/tests/php/unit/View/NoteTest.php index 27aa4fc9..0dba5313 100755 --- a/tests/php/unit/View/NoteTest.php +++ b/tests/php/unit/View/NoteTest.php @@ -21,9 +21,9 @@ public function setUp() public function response_data_should_access_in_Note_View() { $note = array( - "title" =>"PHP", - "body" => "Preprocessor Hypertext" - ); + "title" =>"PHP", + "body" => "Preprocessor Hypertext" + ); $contentTemplateName = 'note'; $output = $this->view->renderContent($contentTemplateName, $note);