Cakephp: MissingControllerException: Controller class AlarmsControllerController could not be found - cakephp

I have a project on Cakephp 2.9.7. When I run test on my local machine I do not get any errors. But, when I try to run ./Console/cake test app Controller/AlarmsController or test any other controller in my docker image, which actually has the same PHPUnit version and Cakephp version, I get an error MissingControllerException: Controller class AlarmsControllerController could not be found. So, the word Controller in the controller name is being used twice. The problem happens in https://github.com/cakephp/cakephp/blob/2.next/lib/Cake/TestSuite/ControllerTestCase.php#L339 this function. So the error trace looks the following way:
/project/lib/Cake/TestSuite/ControllerTestCase.php:347
/project/lib/Cake/TestSuite/ControllerTestCase.php:362
So the error causes the call of getMock function(https://github.com/cakephp/cakephp/blob/2.next/lib/Cake/TestSuite/ControllerTestCase.php#L362). But I cannot undestand what happens there, and why it works on my local machine with equal conditions(PHPUnit, Cakephp version, the same project), but in the docker container I an get error.

You must specify the controller name without the suffix Controller:
./Console/cake test app Controller/Alarms
Docs

Related

CakePHP 3 Audit Log, working with admin routes?

I'm trying to work with this CakePHP 3 plugin which I think does exactly what I need it to do, but am struggling big time! I'm new to CakePHP 3, composer and fiddling with routes etc (previously CakePHP 2.x and manual installation and never played with routes).
The plugin does not appear to be maintained any longer and the package does not exist when trying to install via composer, so I forked it and cloned the files to /plugins/AuditLog/
I've run updated my app composer.json file, loaded the plugin in my bootstrap.php, and run composer install on /plugins/AuditLog/ to load the dependencies from the plugin composer.json file (not sure if this is the right thing to do?)
In plugins/AuditLog/config/routes.php there is the following code
Router::plugin('AuditLog', function ($routes) {
$routes->prefix('admin', function ($routes) {
$routes->fallbacks('DashedRoute');
});
$routes->fallbacks('DashedRoute');
});
So a bit of searching in the CookBook and I read for the first time about 'prefix routing', which from what I can tell means I should be able to reach the pages via /admin/audit-log/audits (for example).
Not surprisingly, I get a missing controller error here
Error: Create the class AdminController below in file: src/Controller/AdminController.php
The instructions for the plugin don't mention anything about creating an admin controller, and there are no controller files anywhere in the plugin at all actually, despite there being views and models.
I'm really out of my depth here, can anyone help me untangle this? Where/how to add which controllers and get them pointing to the right place?

AngularJS loaded twice with Rails asset pipeline

I have set up rails to use bower according to the following guide: http://joelencioni.com/blog/2014/01/03/integrating-bower-with-rails/
I have installed AngularJS and included it in my application.js file.
Now, when I run rake assets:precompile, I get the following error in the console:
WARNING: Tried to load angular more than once.
But my application continues to (seemingly) work fine. When I run rake assets:clobber, I no longer get the error.
I read through the many StackOverflow questions and answers relating to this error and still couldn't find a solution. ng-app is only declared once, there are no errors with my templates and how I include them, turbolinks is removed, etc.
What could cause this error when I compile my assets?
UPDATE: Some strange behaviour here... running the app in production with Passenger, the above error doesn't show up.

CakePHP installation with multiple projects gives `require_once` error on composer

I am trying to run 2 cakephp installations on the same server. However, when I finished setting up the code and the apache vhost settings I ended up getting the following error:
Error: require_once(): Cannot redeclare class composerautoloaderinit922f66fe427c0b7305f553dc8d1952be
File: /var/www/path/app/Vendor/autoload.php
Line: 5
and similarly, on other installation I get:
Error: require_once(): Cannot redeclare class composerautoloaderinit922f66fe427c0b7305f553dc8d1952be
File: /var/www/path_second/app/Vendor/autoload.php
Line: 5
I thought of replacing require_once with just require, but I can't figure out how many includes there will be and what that will do to performance.
I thought of removing one of the folders since apparently its being loaded, but then neither of the two projects I want breaking because at some point for some reason that does not get loaded. Those two projects should be independent.
I wonder if composer should be there at all?!
What should I do?

How to run AngularJS example

I've done as described here: http://docs.angularjs.org/tutorial/step_00 but can't run the phonecat example as AngularJS. It runs like a bunch of html files. For example, the app/index-async.html page gives me following error in Chrome's console:
Uncaught Error: No module: myApp
This file contains
angular.bootstrap(document, ['myApp']);
The bootstrap part needs to be called after the element you're bootstrapping to is loaded. You can either put the bootstrap code at the end of your html, or you can use something like document ready from JQuery.
I had the same problem. When loading angular with reguirejs, you have to remove the ng-app directive from the html and add it after calling angular.bootstrap(document, ['myApp']) like this:
$(html).addClass('ng-app');
Check this seed project out: https://github.com/tnajdek/angular-requirejs-seed specifically index.html and app/js/main.js
Make sure your web server is running.
If you are running node.js:
1. Run node scripts\web-server.js to start the web server
2. In your browser, navigate to http://localhost:8000/app/index.html
If you are running some other http server: (I used WAMP for the AngularJS tutorial you listed):
1. Make sure the /angular-phonecat repository was cloned into your wamp/www folder.
2. Navigate in your browser to http://localhost:[port-number]/angular-phonecat/app.
TIPS:
To change directories using WINDOWS COMMAND LINE -
cd /d c:\wamp\www
To change directories using GIT BASH -
$ cd /c/wamp/www
Additional note: In Git Bash, to display the directory you're currently in, use $ pwd

Loading mocks into an AngularJS unit test

I'm trying to setup my AngularJS application to test out controllers, routes, templates and so on, but I'm having an issue getting some of the helper methods provided by the angular-mocks.js to work (namely module and inject).
I'm using testacular to load up the test suite with the following files added before the specs:
files = [
MOCHA,
MOCHA_ADAPTER,
'../application/lib/angular.min.js',
'./lib/angular/angular-mocks.js',
'./lib/angular/angular-scenario.js',
'../application/application.js',
'./lib/chai.js',
'./lib/chai-should.js',
'./lib/chai-expect.js',
'./spec/**/*.js'
];
So far so good, but when I run the tests I get this issue:
ReferenceError: Can't find variable: module
Not sure where this is loaded. Am I missing something?
First thing to check is that all those files are getting loaded in the test browser. It's surprisingly easy to get a path wrong in your config and not realize it. If you're running testacular with autowatch, you can navigate to http://localhost:9876/context.html with a browser and use developer tools inspect elements/resources/network and see if anything is missing.
If everything is good there and you're still having problems, post some of your test code and I'll take a look.
UPDATE: It appears (strangely) from the comments in the source for angular-mocks.js (line 1635) that window.module is only available with Jasmine. It looks like you're using Mocha instead of Jasmine. This is very likely the culprit.
ANSWER:
I can't rightly take credit for this Matsko, since you figured it out yourself... but it turns out that the current AngularJS stable download and angular-seed contain an older version of ngMock that doesn't support Mocha. Manually replacing the mock file with the latest from the github repo solves the problem. Glad I could help ;-)
I ran into this issue today and I wanted to provide others with a complete summary of the required steps to get this working. First let's say you have a module named myApp. Inside that that module there is a service called myModel. the myModel service has a method named getItems().
Currently, the angular-mocks.js (I am using AngularJS 1.0.6) does not support Mocha. You will need to visit this link and replace the 1.0.6 version with the one in the master branch from the AngularJS GitHub project. An easy way to do this (if you have wget) is wget https://raw.github.com/angular/angular.js/master/src/ngMock/angular-mocks.js in the correct directory. If you use a properly configured Sublime or vim it can also easily pull it down for you.
Make sure your karma.conf.js file includes the angular-mocks.js file in files array
Somewhere in your tests.js file (maybe at the top level describe) include beforeEach(module('myApp')); or whatever you named your main module.
If you plan to use the service (or whatever you want to include in the test) in more than one place you can call another beforeEach where needed like this:
beforeEach(inject(function(myModel) {
mymodel = myModel;
}));
otherwise you just can inject where it is needed. Now the mymodel variable (notice this is the variable you assigned in the beforeEach above) will be available to you for testing in your next blocks. For example, you can now write:
describe('when fetched', function() {
it('should return 3 items', function() {
// console.log(mymodel.getItems());
expect(mymodel.getItems()).to.have.length(3);
});
});

Resources