Can't run tests provided in Slim Framework - php

I'm trying to make a simple rest client for my android app. I would like to do than in TDD way, but for that I need simple working configuration for all actions (GET, POST, and so on). After some struggling I was able to make test work with get requests. Unfortunately with Post routes things didn't go well. When testing (netbeans 8.0.2 + phpunit) on local server (xampp 5.6.3) all I get is 404 error. Same thing if I run method being tested with Advanced Rest Client Application (chrome extension). When I send my rest files to live hosting then method in question works as it should.
After searching for some days (read about everything with 404 errors on Slim Framework) I decided to start with something which should work right of the box. Slim framework comes with simple demo app and some tests. Here I have another error which prevents start of tests:
Fatal error: Class 'Slim\Middleware' not found in C:\xampp\htdocs\web\local\codeguy-Slim-04958a1\tests\MiddlewareTest.php on line 3
As far I can tell I have something wrong with my xampp server but I don't have any more ideas how to fix this. So If somebody could show me correct way to setup Netbeans, Xampp, Slim and phpunit(I'm running it from IDE (ALT + F6)) then I would be able to build my rest api on top of that.

I just tried the following, maybe it might suggest a different route to try?
git clone https://github.com/codeguy/Slim.git
cd Slim
// Edit composer.json to include "phpunit/phpunit": "4.3.*"
curl -sS https://getcomposer.org/installer | php
php composer.phar install
./vendor/bin/phpunit
A few tests failed for me, surprisingly - so that would need digging into. But all classes were found.
Everything should work though, as the project seems to be building OK over on Travis CI.

I've found out what was wrong with my tests and with test provided with framework. I didn't know that I had to set bootstrap.php file in Project configuration of Netbeans.

Related

Microsoft Azure returning 500 Error for a Symfony2 app

wondering if someone can maybe help me out a bit.
I have been working on a project that is a symfony2 web app running on Microsoft azure. it was all working great! i have my code being pulled in from git and i can easily push and update the site.
I then started working on Logins, nothing fancy, i was playing around with HTTP_BASIC athuentication and had it working after following the docs here
http://symfony.com/doc/current/book/security.html
I had a few users and i was pretty happy as id never done this before, my aim down the line is to use doctrine and databases etc but for the moment this will do.
so i had it working locally then i pushed to my branch. and boom 500 error. now i'm not sure what I've done and I've already done a bit of research, but nothing has really helped?
I read somewhere that by removing all the .htaccess files would be a fix, but no avail. the error that i'm getting is just a google 500 error and not a symfony error which makes me that I've really messed it up!
i could roll back to a previously working commit but id lose a lot of work on the front end side, but its confusing how everything is working absolutely fine locally but not on the server... please ask me any questions that could help you help me i guess!
help would be great. also, im a junior!
I built an clear symfony application, configured the security system with HTTP_BASIC authentication on local, and deployed to Azure Web app via GIT. I didn’t have 500 internal error.
So I suspect that there are some errors in the application.
Usually, when we deploy symfony applications to Azure via GIT, there several files and folders will not be updated with the application which may cause the application lack of dependent packages, we can check the list in .gitignore file in root directory.
Login on KUDU console site of your Azure Web App, the URL should be: https://<your _site_name>.scm.azurewebsites.net/DebugConsole, run the following commands in cmdlet:
cd site\wwwroot
(if you do not have composer.phar file in your project)
curl -sS https://getcomposer.org/installer | php
php composer.phar install
It will install the dependences and clear the cache.
Furthermore, we can check whether the application can run in dev mode, visit URL: http://<your _site_name>.azurewebsites.net/web/app_dev.php, if it works fine in dev mode, but rise an error 500 in prod mode known as “app.php”, we should manually clear the production cache:
Login on KUDU console site, and run php app/console cache:clear --env=prod.
If you get a [Symfony\Component\Filesystem\Exception\IOException] exception, you can manually delete app\cache\prod folder and run the command again.
Also, we can check the detail error messages in dev.log and prod.log in app\logs folder.
Beside doing file operations in KUDU console site, we can use WebMatrix on Windows to remote our sites on Azure.

bootstrap.php.cache is missing

I have a problem with Symfony 2. trying the example from the book. I have written a controller but when i go to the URL specified in the route i get an error. The server can't find the page. When i run app_dev.php i get an error that the file boostrap.php.cache is missing.
searched on the internet but found nothing relevant so far. I don't know if the front-controller is already written or if that is something that still has to be done by me.
I can't get the application to run.
Found the solution. I followed the guidelines installing sf2 in netbeans. Instead of running the application as a local website i used the build-in server option wich gave me access to the cli commands. There i could use the command run server and all of my problems were gone.

Setup Yii2 Advanced on Heroku

I am needing some help setting up a Yii2 Advanced Application on Heroku. I have already installed Yii locally using Composer, following their guide exactly: http://www.yiiframework.com/doc-2.0/guide-tutorial-advanced-app.html
My website works as it should locally, with frontend and backend:
http://localhost/yii2app/frontend/web/
http://localhost/yii2app/backend/web/
When I push it and run it on Heroku, I get errors complaining that some files are not found. What is weird, is with a bash terminal to my Heroku app, I can verify that the file is in fact there! Is Heroku not liking the '../../' to change directory?
PHP Fatal error: require(): Failed opening required '/app/frontend/web/../../common/config/main-local.php'
include_path='.:/app/.heroku/php/lib/php') in /app/frontend/web/index.php on line 12
In 'frontend/web/index.php' is Yii's stock code (line 12 is main-local.php):
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/main.php'),
require(__DIR__ . '/../../common/config/main-local.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);
If it had to do with the '../../' to change directory, then I would think the first require would have an error (for the main.php entry).
What am I missing to get Yii2 advanced running on Heroku?
UPDATE - I created a new Yii2 basic app. Should work and be simple, so I thought. Apparently even the basic app does not run on Heroku. There MUST be something left out from the docs, somewhere... Used composer to install Yii2 basic, put it under git, pushed it to a new heroku stack. Went to check out my app on heroku, adding /web/index.php to the end of the url.
ReflectionException
Class yii\debug\Module does not exist
I then put index.php in the root directory containing phpinfo(). I can confirm I get a phpinfo report. So php is running, it reports PHP 5.6.5.
Seems like Yii2 and Heroku do not play well without some magical (and un-documented) tricks. I have searched, and searched, and searched, and I can't find anything about this. I can't possibly be the only one trying to get a Yii app onto Heroku.
So I tried CloudControl. I deployed my stock Yii2 basic app to cloudcontrol, again I get a phpinfo report on the root index.php. Navigate to /web/index.php and get errors:
Invalid Parameter – yii\base\InvalidParamException
The file or directory to be published does not exist: /srv/www/code/vendor/bower/jquery/dist
What gives! I can run this locally just fine. When I push it to a cloud based host (Heroku or CloudControl) it fails! I figured the yiibasic app would be better to at least get it running for PoC, but Yii out of the box, will not run on either of those services. There is something not mentioned that I am missing.
Finally after hours and hours of messing around, I figured it out. Well, I still have one question left that I need to test (and try again). However, I managed to get both the yii basic and yii advanced apps running on Heroku. Still got errors on CloundControl though, but that's for another day.
I was missing 2 entries in my composer.json file. I dunno why these are not included in the Yii documentation if they are required in production. Here is my require block (I did not have to edit the require-dev section, just require):
"fxp/composer-asset-plugin": "*",
"ext-gd": "*"
The composer asset plugin was absolutely required. The GD extension is needed for the contact us page (I assume the captcha). I also commented out the first 2 lines in web/index.php for the YII_DEBUG defines. Once I did that, updated composer, updated git, and pushed, magic happened :)
I don't think they inform you that you need to edit web/index.php to remove them in the Yii2 docs. Seems they are only interested in getting you going for development. Yes the index file has comments, but we need to know to look there! If you don't remove them, Yii will load your debug tools, which don't exist. I assume when Heroku receives the push, it runs composer from the "require" block.
As for the Advanced template.. Frontend and Backend index.php files already have the debugging constants correct for dev and production. You just have to run php init --env=Production --overwrite=All on the server (I couldn't get heroku to do this, but another day). The Yii docs have you run init, then select development. This takes everything from the "environments/dev" folder and overwrite them in their locations in your app. This will fail when in development. So you have to switch it to production, which moves your production files into use. I understand why you would have these, so I get it.. Like I said, I tried heroku run bash, then running php init --env=Production --overwrite=All from the apps directory but it didn't seem to make the switch. So my app was missing the frontend/web/index.php file, and many more.
I was wondering how 'frontend/web/index.php' wasn't even in the directory, but further inspection I saw that many directories have gitignore files. So when you 'git push heroku master', 'frontend/web/index.php' along with the rest, never get pushed because they are ignored. So because I couldn't get Heroku to run Yii's init into production, my files just were not there.
Simple fix to get me running on Heroku with Yii Advanced (including adding the 2 mentioned packages to composer.json): I deleted all the gitignore files, ran init choosing production, updated git, and pushed to heroku. It runs :)
Now I need to figure out how to get init to do this for me so I don't have to delete the gitignore files.
As for this question, it is solved. Heroku can run Yii2 basic and advanced. The biggest issue I see is the Yii docs lacking the necessary composer packages to run in production. So I wonder if it's just Heroku needing those packages...

How can I get a Zend Framework project to run on IIS?

I am trying to get the Zend Framework (ver 9 Studio) to deploy and actually run on my local IIS server.
I have created a very simple little app using the built-in wizard. It works fine if I run it on the Apache server that comes with Zend. But I tried to copy the files over and run it on IIS, and I get errors.
It appears that it is missing the links to the libraries. I've tried manually isolating and grabbing the missing libraries and putting them into the /library folder. This is a good start but I still get other errors down the road.
I found a tutorial out there that comes with an example of a Zend Project that runs in IIS. But, it pretty much has the same problems as the project I created. More missing libraries. The tutorial includes some neat new tricks like a web.config that is supposed to replace the need for the .htaccess that Apache uses.
That's how far I've made it. This is all very frustrating. Does anyone have a simple example like that tutorial promised? If not, just some good information would be helpful.
you need the rewrite module, Rob Allen has a little tutorial to help. The biggest problem is usually the rewrite module, because you have to install it seperately.

PHP Command Line running, zend framework set up problem

Im trying to learn how to set up a Zend framework web application from scratch. Ive been using Magento and I understand how powerful Zend is, but im over my head it seems like.
So I bought a book, developing web applications with Zend 1.8 by Keith Pope, and I cant even follow past the first chapter. The thing that is confusing the hell out of me is the whole command line deal.
Here is a passage from the book --
Once we have downloaded the Zend Framework release package, we need to do some basic installation before we can start creating our application. First, create a new directory within your web server's document root, from which the application will be served. The examples in this chapter use the directory name of helloZend. Next, copy the library and bin directories from the release package into the newly created directory. The library directory contains all of the Zend Frameworks
source files, and the bin directory contains the command line interface for the
Zend Framework. The Zend Framework is now installed and ready for use!
Creating the project structure
We are now ready to start creating the directory structure for our project. In order to do this, we are going to use the command line interface provided by the Zend Framework. This interface uses the Zend_Tool component that provides a whole host of commands that makes it very easy to get up and running with the Zend Framework in just a few minutes.
In order to create the project structure, open up your command line and change into the hellozend directory, and then run the following command:
For Windows users:
bin\zf.bat create project
For Linux and Mac users:
bin/zf.sh create project
Ok so Ive done all that. But up above in first part he says upload it to your web server, did that already. But then "open up your command line", how exactly do I do this? The only command line I understand I can access is Terminal, do I do something with Terminal or??? (Im on a mac) - I tried navigating straight to bin/zf.sh on my webserver and it brought up a what do you want to open this link with, I chose terminal and nothing happened.
Can someone clarify this for me? I realize this may be a stupid question, but I have zero experience working with non live servers and what not....
I've been a ZF developer for several years, but was working on a pre- 1.5 version up until very recently (not by choice) I found it easiest to build a local version on my machine via ZendServer CE, then once all was running and stable, port it over to my dev server. Because I have full root permissions locally, I didn't run into any issues of naming/permissions as I walked through the initial tutorial of new features and initial setup.
Also, don't miss Akrabat's tutorial on getting started the ZF. It's very well written and in some cases easier to understand than the quickstart: http://akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework.pdf
I don't say this to developers often, but you are in over your head if you don't yet understand how to open and use a command-line shell. Your question is not stupid -- everyone has to get started somewhere. But Stack Overflow is a place for specific questions about programming, like "I tried X and it didn't do what I expected, how should I code it instead?"
All I can suggest to you is to start studying. I believe that it's counter-productive to try learning new tools at the same time as trying to get a project done. So spend some time just learning the Terminal interface and how to run things in that environment.
Google for "Mac Terminal tutorial" and a bunch of useful articles and YouTube videos come up. Start there.
I also recommend "Mac OS X: The Missing Manual".
Re your comment: Okay, I think I'm seeing the source of your confusion. What the excerpt is not saying is that you need to open a shell on the host where you're developing your ZF app. What I do is to develop the project on my local host (my Macbook) so I can have quick access for moving files around and so on. This means I run an instance of Apache running on my Mac.
Then at intervals, when the app is running and done with respect to a given milestone of functionality, I upload the whole set of files I developed to my production server.
Tell me if I'm getting warmer. I really can't tell what you know and what you don't know because of the way you've asked your question.
anyone who needs the basic understanding of connecting to a webserver via terminal or command line via ssh should read the following:
http://www.elated.com/articles/ssh-and-basic-commands/
Although, the information there didn't work with my particular webhost. I had to format the connect command like this:
ssh user#host -p 1234
Where 1234 is the servers port number, which you will need to get from your webhost if you dont know it.
To run that script, navigate to directory where you've uploaded it (you open terminal, connect to your server via ssh if you're doing this remotely).
After that execute it like this:
./zf create project your_project_name
It should create new dir named "your_project_name" and in it many other sub-directories for your application.
Also, I'd recommend that you go for http://framework.zend.com/manual/en/learning.quickstart.html instead that book - Quick Start really is great.

Categories