CodeIgniter 2.1 and SimpleTest - Conducting a simple test - php

I am currently using CI 2.1 and Netbeans 7.0 as my inveiglement IDE. I would like to create some simple unit testing using SimpleTest. In particular the methodology used by Eric Barnes and his code found at Git Hub CodeIgniter-SimpleTest. (https://github.com/ericbarnes/codeigniter-simpletest)
I have created a new CI application using Netbeans 7.0 and connected to my database (which contains 1 table called schools with the typical schema schoolid, schoolname, schooladdress etc.). I have created a controller (simpleapp), which loads a model called schools_model. The schools_model gets all the schools using a method called getAll(). Another method called getSchoolName(id), accepts a school ID and returns the school name.
The controller then loads a view called schools_view to display all the schools. Pretty simple stuff…....... and it works flawlessly, displaying all the schools when I point my browser to
http://localhost/SimpleTest/simpleapp/getAllSchools
(I am also using a .htaccess file, hence no index.php)
My question is this….......
How do I get SimpleTest to work using the Git hub code supplied by Eric?
I have followed Eric’s set-up advise, but don’t know what URL to point to to create the screen dumps he provides. I have maintained the directory structure Eric suggests but haven’t had any success. Eric suggest to point the browser to yoursite.com/unit_test.php, but I get a
404 page not found error for localhost/SimpleTest/unit_test.php
I assume the above error is due to the fact, like most CI applications, we need to use a controller first.
I would appreciate any direction in this area.
I have done exactly what you suggested. I have placed the unit_test.php file in the root directory and set up the test directory structure as suggested. However, when I point to localhost/SimpleTest/unit_test.php I get the 404 error.
My directory structure looks like
Source Files
-application (folder)
-system(folder)
-tests(folder from git hub with model/test_schools_model.php)
-.htaccess
-index.php
-licence.txt
-unit_test.php
Is it a .htaccess issue the reason I cannot view localhost/SimpleTest/unit_test.php?

You are correct you need to go to yoursite.com/unit_test.php or in your case localhost/SimpleTest/unit_test.php
You need to copy the unit_test.php file from github into the sites root directory and place the tests directory there too. You then put your tests in the appropriate folder under tests/

Related

Slim4 through openapi-generator deployment problems

I've been working on this for several days now and I'm at the point of pulling my hair out.
Goal: to deploy Slim4 on my LAMP server within a specific subdirectory and accessible via a simple URL.
Structure:
There are several instances of my web app on the server and the setup should be replicated for all of them; the structure is straight forward:
/var/www/company1.com/app
this "app" folder contains the main index.php of the website, as well as other various folders. Eg. /var/www/company1.com/app/index.php => https://company.com/index.php
there is a folder called "api" within which I want to load Slim4. I don't really mind how this folder is structured and how deep it goes. I'm working on basis that this is where the composer file goes.
the end result should be that the customer can access the api by calling https://company1.com/api
I'm using the openapi-generator and the Pet Store yaml file.
Running:
openapi-generator-cli generate -i petstore.yaml -g php-slim4 -o /var/www/company1/api/
I've then run composer install and setup the config.inc.php file as described in the instructions.
However when I navigate to http://company1.com/api I am greeted with the same issue every time:
404 Not Found Type: Slim\Exception\HttpNotFoundException Code: 404 Message: Not found. File: /var/www/company1.com/app/api/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php Line: 91 Trace: #0 /var/www/company1.com/app/api/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(58): Slim\Middleware\RoutingMiddleware->performRouting() #1 /var/www/company1.com/app/api/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\RoutingMiddleware->process()
it goes on...!
I can't figure this problem out.
This issue seems to be quite common as there are a lot of posts about it, so I'm convinced I've missed something very simple.
I have tried the following:
Setting the base path
$app->setBasePath("/api");
Creating a /public/ folder and moving the index.php file there, then creating two different .htaccess files, based on these instructions:
https://akrabat.com/running-slim-4-in-a-subdirectory/
using basepath as per its instructions
https://github.com/selective-php/basepath
None of it seems to work! What am I doing wrong?
I have been able to successful load the Slim4 Skeleton application, however I want to use the openapi-generator so that I can have it automatically prepare all the php files based on my openapi yaml spec.
Any thoughts on tips would be greatly appreciated!

Cakephp Requires Controller

Can anyone help me,
i developed my application with Cakephp 2.1, and it works fine on my development server running Centos 5.7. My challenge came when i transfer my application to the lice server to be accessed by on LAN. It states that a missing controller which is not available in my whole application, for example, i named my folder which contains my application and uploaded to the correct folder in Centos, e.g /var/www/html/students and every time i need to access the application states that students controller is missing. I tried to rename my folder to 'mysite' and the errors still remain with mysite controller is missing.
So everytime i changed the name of the folder it states a missing controller for that named folder. I tried to figure out in core.php but cant find the solution.
To change the base directory to say /mysite you will have to modify your 3 .htaccess of cakephp i.e one in installlation folder , second inside the app folder,third inside the webroot folder
try adding:-
RewriteBase /mysite/
Hope this helps!

CakePHP Shared core for multiple apps

On my local setup I have a load of different CakePHP websites. I'm using a Mac so the folder structure is something like ~/Users/cameron/Sites/sample-website and then within each of these websites I will have the typical Cake folder and App folder.
What I would like to do is have just a core cake folder and then have ALL the sites pull from that one cake core so I don't have the same stuff several times over. I have been reading some tutorials on the web: http://rickguyer.com/cakephp-one-core-many-apps/
So I have my cake folder here: ~/Users/cameron/Sites/cake-1.3/ and then my site here: ~/Users/cameron/Sites/sample-site/ and in this folder I have the usual app folder and htaccess to tell it where to find webroot etc.
Now I have edited the index.php file inside webroot like the tutorial BUT have only changed one line because I haven't moved my files OUTSIDE of the App folder like he does. So the only like I have changed is as follows:
if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
define('CAKE_CORE_INCLUDE_PATH', '..'.DS.'..'.DS.'cake-1.3');
}
As far as I can tell that is correctly looking two directories up and finding a folder called cake-1.3 however it just gives a error 500?
Any ideas what the problem is? Thanks
EDIT:
Even doing this doesn't work???
Which If I echo: echo CAKE_CORE_INCLUDE_PATH; gives /Users/cameron/Sites/cake-1.3 and if I paste that in the address bar it loads up the cake folder so it's definitely the correct folder structure JUST it doesn't like looking at cake outside of the main url?
if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3'); echo CAKE_CORE_INCLUDE_PATH;
}
You are right on the money with:
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');
Just make sure that Users sits in root. In other words, when you go to terminal you can get to this directory by typing: cd /Users/cameron/Sites/cake-1.3
It looks like you may be on a MAC. If so, your linking is correct. Most of the time what I find is you have done a copy paste of the app directory and it does not get the .htaccess files. I would check those first. But here is a comprehensive list of what you should verify:
Make sure the host is pointing to
the correct directory
(/Users/cameron/Sites/sample-site/)
Verify mod_rewrite is in fact on.
Verify you have copied the .htaccess
file in both the
/Users/cameron/Sites/sample-site/
and the
/Users/cameron/Sites/sample-site/webroot
directories.
Confirm that the
/Users/cameron/Sites/cake-1.3/
directory has a directory called
cake in it that contains the core.
Once all of this is confirmed, you will be good as gold!
Happy Coding!
UPDATE:
When the index.php file looks for the cake core, it will look for a directory inside the location you are pointing to for another directory called cake. So in your case:
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');
You must have the cake directory inside /Users/cameron/Sites/cake-1.3. Your directory structure will look like:
/Users/cameron/Sites/cake-1.3/cake
/Users/cameron/Sites/cake-1.3/cake/libs
/Users/cameron/Sites/cake-1.3/cake/config
/Users/cameron/Sites/cake-1.3/cake/console
etc.
CakePHP 3.0+
In CakePHP 3.0+ this configuration is moved out of webroot/index.php to App/Config/paths.php
If you have access to your php.ini, you can add the path to Cake core there. Doing it this way means you don't have to change webroot/index.php at all. Example in php.ini:
include_path = ".:/usr/local/lib/php:/home/something/phpinc/cakephp2/lib"
According to the CakePHP 2.x docs, this is the recommended way to share the Cake core (assuming you have access to your php.ini).
You can have only one cake core but you must have one app folder (containing MVC) by site.
Is this a misunderstanding of the folder structure of CakePHP?
From the docs (CakePHP folder structure):
The app folder will be where you work your magic: it’s where your application’s files will be placed.
The cake folder is where we’ve worked our magic. Make a personal commitment not to edit files in this folder. We can’t help you if you’ve modified the core.
So the cake folder shouldn't change between all of your uses, therefore you have 1 copy. You can always change some of the functionality of the core by making your own changes in the app folder i.e. extending.
There is no need to edit index.php.
Just put an alias (or link in UNIX) to your cake folder in each of your sites folder. Works perfectly. Same goes for plugins and vendors folder.

CakePHP Missing Controller - but it exists

I recently downloaded cakephp-1.3.4. I set it up on my web server. I followed the advanced installation settings. My folder structure is as follows.
/common/
cakephp/
app/
etc...
/htdoc/
The /htdoc folder is the webroot; cakephp resides in the common folder.
I have configured the paths in index.php to point to this folder structure. I have the app up and running. I created a layout, the app has picked it up (along with all the css and images - all that works).
I created a posts_controller.php in cakephp/app/controllers/. Now when I try to access the following page: http://localhost/posts. I get a message that the controller cannot be found and that I should create a app/controllers/posts_controller.php (it already exists!).
Also the strange thing is using the default pages_controller works. I created an about.ctp and dropped it in app/views/pages/about.ctp. Vising http://localhost/pages/about shows up as expected.
SOLUTION:
Sam helped me solve this problem (see the long comment thread below). The problem was I had set relative paths for my ROOT folder. This messed things up. The solution is to either directly set an absolute path or call realpath with your relative path for it to be resolved into the right absolute path.
Make sure your controller class is named correctly (should be PostsController) and inherits from AppController (not strictly necessary but good practice).

How do I get CakePHP configured so it shows up correctly in my browser?

I am a cakephp newbie and I had trouble to view the files under the view folder through browser.
I used cakephp console to bake model, controller and views. (ex: Invoices_controller.php for controller, invoice.php for model and a invoices folders under views folder). According to the tutorial I read, I can access the invoice view by typing http://localhost/myProject/invoices
(there is no index.php inside the invoices folder..but the tutorial shows it still can display a page. no idea how they did it)
The path for my invoices is myProject/views/invoices and there add.ctp, index.ctp, edit.ctp files inside the invoices folder.
The browser showed the file is not found when I typed http://localhost/myProject/invoices
You have some lack in your knowledge about how the webserver handling a request when cakephp is installed. Assume that we use apache.
In cake's folder structure you can see .htaccess files in the root, app and webroot directories what have url rewrite rules in them. At the end a normal request to a cakephp site will be transformed to a http://site.url.root/app/webroot/index.php?url=original.url
In nutshell to understand it in your point of view:
That index.php call the required php files and at least a cakephp app object is built up in the memory with the required models and methods. Then the app object let say start and calls its methods (model, controller and view methods) and at the end it gives back a result to apache what serves it to you.
Therefore the original url path is a "non existent" virtual url.
If you enter http://localhost/myProject/ do you get a cake intro page? If so does it highlight any problems?
It sounds to me as if you do not have Apache set up properly. I don't know what OS you're using, but it might be worth checking this link, written for Ubuntu, to make sure all is well: http://leoponton.blogspot.com/2010/05/getting-cakephp-up-and-running-on.html
I fixed the same problem.
if you are using windows 7 os, wamp server, cakephp 2.2.3. then
goto apache -> http.conf -> open -> search for mod_rewrite -> uncomment the line LoadModule rewrite_module modules/mod_rewrite.so
Now restart your server, now it should work fine.
Jerry, I think the issue is this. You have put the CakePHP folder in the root of localhost. I would propose that you create a virtual host pointing the myProject so the url becomes:
http://myProject/accounting
This may solve your problem. Be sure rewrite module is on. Also, when you point the virtual host to myProject, it should be the APP folder of the cakephp. If you want to run multiple projects off the same core, you can set them up like so:
/var/www/cake
/var/www/html/myProject
/var/www/html/myProject2
The /var/www/cake directory is where you drop the cake core. Under this directory you will have cake, app, plugins, vendors, etc. the myProject(2) directories will be the contents of the app directory.
Now, to get this to work, you need to go to /var/www/html/myProject/webroot/index.php and edit it to point to the cake directory in /var/www/cake. This will then load the core when rewrite points to index.php in webroot. You should be good to go!

Categories