Skip to content

mhavelant/gm-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

##General:

  • The application was written in NetBeans 8.0.2 IDE, with PSR-2 coding standard.
  • It's built on the Symfony 2.7.5 framework.
  • Dev. environment:
  • Windows7 64bit
  • Apache 2.4.9 (Win64) [Installed from WAMP]
  • PHP 5.5.12 [Installed from WAMP]
  • MySQL Community Server (GPL) 5.6.17 [Installed from WAMP]

##Installation:
###Prerequisites

  • The project needs ~60 MB of storage space.
  • The application requires WAMP/LAMP to be installed and running.
  • You also need composer.
  • For testing I used PHPUnit (phpunit.phar v4.8.10 included in the repo).

###Installation
When everything is up and running, follow these steps [read first, act later!]:

  1. Download and extract/clone the repo to the desirable folder.
  2. Open terminal/command line and navigate to the project folder.
  3. Use mysql -u [user] -p[pass] < Create_Database.sql to prepare the database and tables.
    • Note: no space is needed between -p and your password.
  4. Execute the composer install command. This will download the dependencies. During the installation, you'll be asked to fill out database and mailer information:
    • The database name should be GMTest
    • For other informations (database host, etc.) use your own settings.
    • For switmailer you can use your own information or my settings from Sending information.

##Starting the application:

  • Navigate to the project folder in the terminal (linux) or command line (windows) and excute the command:
    php app/console server:run
  • Now you can use the api. Base path is 127.0.0.1/api/{rest_function_name}.
  • Replace {rest_function_name} in your request with the needed function.

##API function list:

  1. current_temperature

    • Method: GET
    • Description: Returns the current temperature (in celsius) in Budapest.
  2. email_temperature

    • Method: POST
    • Description: Sends the current temperature to the specified email address.
    • Data type: json
    • Data format: {"to": "email of the recipient"}
  3. current_temperature

    • Method: GET
    • Description: Send the current temperature to the specified email address in every hour.
    • Data type: json
    • Data format: {"to": "email of the subscriber"}

##Using cURL to send requests to the API:

##Sending information:

  • Sending emails is achieved with SwiftMail.
  • I use Mandrill as my mail server.
  • My settings
  • mailer_transport: smtp
  • mailer_host: smtp.mandrillapp.com
  • mailer_user: [email protected]
  • mailer_password: dfMdvig0VJkYl-EVxNFhPQ
  • mailer_port: 587

###Manual sending:

  • I defined a command in the project: crontasks:run
  • In the terminal (linux) or command line (windows) go to the project folder, and execute: php app/console crontasks:run
  • If the email for the subscriber is expected to be sent, the the command will send it. Otherwise the email is skipped.

###Automate sending

###Automatic tests

  • Important! For running the tests, please restart the server in test mode: php app/console server:run --env=test
  • All three functions have unit tests.
  • Navigate to the projectfolder, and execute php phpunit.phar -c app to run all tests.
  • Execute php phpunit.phar -c app --coverage-html chtml to also get the coverage analysis of the tests.
  • The coverage is generated to ../ProjectFolder/chtml and you can view it by opening the index.html in your browser.
  • Note: Since some parts of the code require the used weather API to be unavailable, 100% coverage is unlikely.

##Other notes

  • I wrote the project in symfony, because i'm the most comfortable with this framework. If required, I will rewrite it in Laravel.
  • The CronTaskRunCommand class needs heavy refactoring. I just copypasted code from the API controller, to speed things up.
  • Having those 2 tables in the database might also be redundant.
  • ToDo: Use better and more exception handling.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages