title: Orchestrating Non-JavaScript Backend from Protractor Test
body: <p>I am writing an application which has a LAMP backend, which provides a RESTful API. This API is consumed by an AngularJS front-end.</p>
  
  <p>I have unit and integration tests for the API / GUI in isolation. Now I am expanding my test horizon to encompass a full front-to-back test suite.</p>
  
  <p>I've been playing around with <a href="https://angular.github.io/protractor/" rel="nofollow noreferrer">Protractor</a>, which has been extremely useful for the browser-based inputs for my front-to-back tests.
   However, I'm strugging to see how I can integrate this with the orchestration of the PHP backend.</p>
  
  <hr>
  
  <p>Within the PHP integration tests, I have a set of utility classes that populate the system (i.e. database) with a pre-determined universe. For example; there is a pre-created user called "Bob", and an administrator called "Alice".</p>
  
  <p>Between each integration test case, the entire universe is re-set to this base state, so that any interactions with Bob  &amp; Alice in the test are re-set.</p>
  
  <p>This is one example of the orchestration I would like to manage from Protractor. However, I cannot see an easy pattern to integrate with the PHP code which constructs the test universe.</p>
  
  <p>After the initial population of the world, there are other orchestration tasks I would like to be able to execute to get the system into the desired target state; e.g. locking Bob's user account.</p>
  
  <p>Without wanting to access the MySQL DB directly from the protractor code, how can I re-use my PHP logic and invoke the business logic from Protractor?</p>
  
  <p>I could offer RESTful orchestration URLs. But this seems dangerous, as it would pose a serious risk if ever released to production.</p>
  
  <hr>
  
  <p>There are a number of suggestions on other StackOverflow questions (e.g. <a href="https://stackoverflow.com/questions/20518687/angular-e2e-tests-affecting-database">this one</a>) which suggest using Mocks. These seem to completely miss the mark; given protractor is designed for front-to-back tests.</p>
  
  <hr>